Author Topic: IRC Client Integration  (Read 38687 times)

0 Members and 1 Guest are viewing this topic.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: IRC Client Integration
« Reply #15 on: June 27, 2011, 04:37:18 pm »
Nice stuff! :D Just a friendly poke that XChat can support Python, Perl, and TCL (the former being the most popular), so you can have a bit more portability. ;)
(I can't compile that plugin until I dig out some archives for the needed headers - surprisingly, XChat on Linux doesn't come with them, but they are installed when compiling XChat2 source.)

Except those extensions require hundreds of megs of extra libs on Windows.


Also, here's an updated mIRC script, it supports timestamps.
Code: [Select]
ON ^*:TEXT:*:#:if ( $nick == OmnomIRC ) { echo $chan $iif($regsubex($readini($mircini,options,n4),/(^(.+?,){11}(.+?).*)/,\3) == 1,$timestamp,) $iif( $mid($1-,2,1) == $chr(35) , (4 $+ $chr(35) $+ ) $+ $mid($1-,4), (12O) $+ $mid($1-,7) ) | haltdef }

Also, OmnomIRC doesn't have an alt nick anymore, since I switched to the PHP bot. It'll just keep retrying with OmnomIRC until the server lets it in.
Ah ok thanks for the update and info :)

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: IRC Client Integration
« Reply #16 on: June 27, 2011, 04:37:37 pm »
You can also use
Code: [Select]
/load "/path/to/file"
Or, on windows
Code: [Select]
/load "c:\path\to\file"
Omnimaga Admin

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: IRC Client Integration
« Reply #17 on: June 27, 2011, 04:38:09 pm »
Here's the compile command:
g++ -Wl,--export-dynamic -Wall -O1 -shared -fPIC -std=c++0x -I/usr/include/xchat OmnomIRC_XChat_Plugin.c -o OmnomIRC_XChat_Plugin.so

One minor fix needed - you need to add
Code: [Select]
#include <stdio.h>
#include <tr1/type_traits>
...so things compile! :)

Here's the updated source:
Code: [Select]
#include "xchat-plugin.h"
#include <string.h>
#include <string>
#include <cstdlib>
#include <regex>
#include <iostream>
#include <tr1/type_traits>
#define PNAME "OmnomIRC Integration"
#define PDESC "Integrates OmnomIRC into X-Chat"
#define PVERSION "0.1"

static xchat_plugin *ph;   /* plugin handle */
static int enable = 1;
static char omnomIRC_Name[] = "OmnomIRC";
using namespace std::tr1;
using namespace std;
//#define debug
static void dbgPrint(const char *message)
{
#ifdef debug
xchat_print(ph,message);
#endif
}
static void dbgPrint(string message)
{
#ifdef debug
xchat_print(ph,message.c_str());
#endif
}
static string getMessageType(string message)
{
if (regex_search(message.begin(),message.end(),regex("^.{0,3}\\((.)\\).{0,1}<(.+?)> (.*)")))
return "message";
if (regex_search(message.begin(),message.end(),regex("^.{0,4}\\((.)\\)([^:space:]{0,4})\\* ?(.*)")))
return "action";
return "";
}
static char* getNameColor(const char *name)
{
char *rcolors[] = {"19", "20", "22", "24", "25", "26", "27", "28", "29"};
int sum = 0, i = 0;
while (name[i] != '\x00')
sum += name[i++];
sum %= 9;
return rcolors[sum];
}
static int on_text_cb(char *word[], void *userdata)
{
if (strcmp(word[0],omnomIRC_Name))
{
string messageType = getMessageType(word[2]).c_str();
string type = word[0];
cmatch parts;
if (strcmp(messageType.c_str(),"message") == 0)
{
regex rx("^.{0,3}\\((.)\\).{0,1}<(.+?)> (.*)");
regex_search(word[2],parts,rx);
bool omnomirc = parts[1].str().c_str()[0] == 'O';

string name;
if (omnomirc)
{
name.append("\x03""(\x03""12O\x03"")\x03");
name.append(getNameColor(parts[2].str().c_str()));
}
else
{
name.append("\x03""(\x03""4#\x03"")\x03");
name.append(getNameColor(parts[2].str().c_str()));
}
name.append(parts[2]);
string msg;;
msg.append(parts[3]);
parts[2].str();
if (xchat_nickcmp(ph,xchat_get_info(ph,"nick"),parts[2].str().c_str()) == 0)
xchat_emit_print(ph, "Channel Message",name.c_str(), msg.c_str(), "@", NULL); //Don't highlight on local messages
else
xchat_emit_print(ph, type.c_str(), name.c_str(), msg.c_str(), "@", NULL);
return XCHAT_EAT_ALL;
}
else if (strcmp(messageType.c_str(),"action") == 0)
{
regex rx("^.{0,3}\\((.)\\)([^:space:]{0,4})\\* ?(.*)");
regex_search(word[2],parts,rx);
bool omnomirc = parts[1].str().c_str()[0] == 'O';
string name = "\x03""\x03";
if (omnomirc)
name.append("12O\x03""18 *");
else
name.append("04#\x03""18 *");
string message(parts[2]);
message.append(parts[3]);
xchat_emit_print(ph, type.c_str(), name.c_str(), message.c_str(), "@", NULL);
return XCHAT_EAT_ALL;
}

}

   return XCHAT_EAT_NONE;
}

void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
{
   *name = PNAME;
   *desc = PDESC;
   *version = PVERSION;
}

int xchat_plugin_init(xchat_plugin *plugin_handle,
                      char **plugin_name,
                      char **plugin_desc,
                      char **plugin_version,
                      char *arg)
{
   /* we need to save this for use with any xchat_* functions */
   ph = plugin_handle;

   /* tell xchat our info */
   *plugin_name = PNAME;
   *plugin_desc = PDESC;
   *plugin_version = PVERSION;

   xchat_hook_print(ph, "Channel Message", XCHAT_PRI_NORM, on_text_cb, NULL);
   xchat_hook_print(ph, "Channel Msg Hilight", XCHAT_PRI_NORM, on_text_cb, NULL);

   xchat_print(ph, "OmnomIRC Integration loaded successfully!\n");

   return 1;
}

EDIT: Forgot to add "#include <tr1/type_traits>" to things to add. Sorry!
« Last Edit: June 27, 2011, 04:42:56 pm by alberthrocks »
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: IRC Client Integration
« Reply #18 on: June 27, 2011, 04:40:46 pm »
@netham tcl isn't a massive setup on windows, unlike python and perl.

Also, why the cstring instead of string? is it better? It seems like it might be smaller....

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: IRC Client Integration
« Reply #19 on: June 27, 2011, 04:41:01 pm »
Here's the full Windows project.
Omnimaga Admin

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: IRC Client Integration
« Reply #20 on: June 27, 2011, 04:42:21 pm »
Wow the X-Chat script is so much larger than the mIRC one. Is it because it's lower level or something? O.O

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: IRC Client Integration
« Reply #21 on: June 27, 2011, 04:43:32 pm »
mIRC makes it easy to do this stuff, I had to make a C++ dll for X-Chat to get it to do it. The mIRC one took me like 5 minutes, the stupid X-Chat one took me a couple hours (Those damn regex libs make no sense what-so-ever)
Omnimaga Admin

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: IRC Client Integration
« Reply #22 on: June 27, 2011, 04:43:32 pm »
alberthrocks, I don't think you need all these libraries... Get my version to keep it simple and optimized. Unless my version doesn't work at all.

Code: (xchat_omnomirc.cpp) [Select]
#include "xchat-plugin.h"
#include <cstring>
#include <cstdlib>
#include <regex>
#include <iostream>
#define PNAME "OmnomIRC Integration"
#define PDESC "Integrates OmnomIRC into X-Chat"
#define PVERSION "0.1"

static xchat_plugin *ph;   /* plugin handle */
static char omnomIRC_Name[] = "OmnomIRC";
using namespace std;
//#define debug
#ifdef debug
static void dbgPrint(const char *message)
{
xchat_print(ph,message);
}
static void dbgPrint(string message)
{
xchat_print(ph,message.c_str());
}
#endif
static string getMessageType(string message)
{
if (regex_search(message.begin(),message.end(),regex("^.{0,3}\\((.)\\).{0,1}<(.+?)> (.*)")))
return "message";
if (regex_search(message.begin(),message.end(),regex("^.{0,4}\\((.)\\)([^:space:]{0,4})\\* ?(.*)")))
return "action";
return "";
}
static char* getNameColor(const char *name)
{
char *rcolors[] = {"19", "20", "22", "24", "25", "26", "27", "28", "29"};
int sum = 0, i = 0;
while (name[i] != '\x00')
sum += name[i++];
sum %= 9;
return rcolors[sum];
}
static int on_text_cb(char *word[], void *userdata)
{
if (strcmp(word[0],omnomIRC_Name))
{
string messageType = getMessageType(word[2]).c_str();
string type = word[0];
cmatch parts;
if (strcmp(messageType.c_str(),"message") == 0)
{
regex rx("^.{0,3}\\((.)\\).{0,1}<(.+?)> (.*)");
regex_search(word[2],parts,rx);
bool omnomirc = parts[1].str().c_str()[0] == 'O';

string name;
if (omnomirc)
{
name.append("\x03""(\x03""12O\x03"")\x03");
name.append(getNameColor(parts[2].str().c_str()));
}
else
{
name.append("\x03""(\x03""4#\x03"")\x03");
name.append(getNameColor(parts[2].str().c_str()));
}
name.append(parts[2]);
string msg;;
msg.append(parts[3]);
parts[2].str();
if (xchat_nickcmp(ph,xchat_get_info(ph,"nick"),parts[2].str().c_str()) == 0)
xchat_emit_print(ph, "Channel Message",name.c_str(), msg.c_str(), "@", NULL); //Don't highlight on local messages
else
xchat_emit_print(ph, type.c_str(), name.c_str(), msg.c_str(), "@", NULL);
return XCHAT_EAT_ALL;
}
else if (strcmp(messageType.c_str(),"action") == 0)
{
regex rx("^.{0,3}\\((.)\\)([^:space:]{0,4})\\* ?(.*)");
regex_search(word[2],parts,rx);
bool omnomirc = parts[1].str().c_str()[0] == 'O';
string name = "\x03""\x03";
if (omnomirc)
name.append("12O\x03""18 *");
else
name.append("04#\x03""18 *");
string message(parts[2]);
message.append(parts[3]);
xchat_emit_print(ph, type.c_str(), name.c_str(), message.c_str(), "@", NULL);
return XCHAT_EAT_ALL;
}

}

   return XCHAT_EAT_NONE;
}

extern "C" void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
{
   *name = PNAME;
   *desc = PDESC;
   *version = PVERSION;
}

extern "C" int xchat_plugin_init(xchat_plugin *plugin_handle,
                      char **plugin_name,
                      char **plugin_desc,
                      char **plugin_version,
                      char *arg)
{
   /* we need to save this for use with any xchat_* functions */
   ph = plugin_handle;

   /* tell xchat our info */
   *plugin_name = PNAME;
   *plugin_desc = PDESC;
   *plugin_version = PVERSION;

   xchat_hook_print(ph, "Channel Message", XCHAT_PRI_NORM, on_text_cb, NULL);
   xchat_hook_print(ph, "Channel Msg Hilight", XCHAT_PRI_NORM, on_text_cb, NULL);

   xchat_print(ph, "OmnomIRC Integration loaded successfully!\n");

   return 1;
}

EDIT: Also removed a warning about a function being unused.
EDIT2: Removed more unused stuff. So you should only see deprecated conversion from string constant to ‘char*’ warnings.
EDIT3: Fixed symbol issue.
« Last Edit: June 28, 2011, 03:59:07 am by Juju »

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: IRC Client Integration
« Reply #23 on: June 27, 2011, 04:44:13 pm »
Yeah miRC is a lot simpler to write something like this for. XChat you have to write in a lot more things
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: IRC Client Integration
« Reply #24 on: June 27, 2011, 04:44:42 pm »
Wow the X-Chat script is so much larger than the mIRC one. Is it because it's lower level or something? O.O
Yup, pure C++ at it's best. ;) I think I could port this to Python, not sure.
The reason I say Python is because it's offered on most, if not all, Linux systems (including Macs! O_O), but not Tcl.
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: IRC Client Integration
« Reply #25 on: June 27, 2011, 04:45:47 pm »
Thanks Juju, now I could compile it :D
One thing: gcc should be c++ :)

Edit: Apparently I did something wrong:
Code: [Select]
/home/jim/xchat_omnomirc.so: undefined symbol: _ZSt12regex_searchIPKcSaISt9sub_matchIS1_EEcSt12regex_traitsIcEEbT_S7_RSt13match_resultsIS7_T0_ERKSt11basic_regexIT1_T2_ESt6bitsetILj11EE
« Last Edit: June 27, 2011, 04:50:15 pm by jimbauwens »

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: IRC Client Integration
« Reply #26 on: June 27, 2011, 04:53:49 pm »
Hmmm, I get this:
Code: [Select]
AutoLoad failed for: /home/julien/.xchat2/xchat_omnomirc.so
 Le symbole xchat_plugin_init n'existe pas ; est-ce vraiment un greffon xchat ?

Looks like the symbols get incorrectly exported.

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: IRC Client Integration
« Reply #27 on: June 27, 2011, 04:56:17 pm »
Here's an mIRC code that should strip Spybot45 and format Saxjax messages. Since I'm wrongfully banned in #cemetech still, I can't really test the Saxjax part of it.

Code: [Select]
ON ^*:TEXT:*:#:{
  var %timestamp $chr(20)
  if ($regsubex($readini($mircini,options,n4),/(^(.+?,){11}(.+?).*)/,\3) == 1) { var %timestamp $timestamp }
  if ( $nick == OmnomIRC ) { echo $chan %timestamp $iif( $mid($1-,2,1) == $chr(35) , (4 $+ $chr(35) $+ ) $+ $mid($1-,4), (12O) $+ $mid($1-,7) ) | haltdef }
  if ( $nick == Saxjax ) { echo $chan %timestamp $regsubex( $1- ,\((.)\).\[(.+?)\] (.*),( $+ 5\1 $+  $+ ) <\2> \3) | haltdef }
}
« Last Edit: June 27, 2011, 05:16:22 pm by Netham45 »
Omnimaga Admin

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: IRC Client Integration
« Reply #28 on: June 27, 2011, 05:06:49 pm »
Yay it works :D

I might make using #cemetech and #omnimaga easier now, especially if I'm not using full screen windows.

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: IRC Client Integration
« Reply #29 on: June 27, 2011, 05:07:27 pm »
That's why I made it. I was having trouble keeping track of convos when the names were everywhere.
Omnimaga Admin