EvilZone
Programming and Scripting => Scripting Languages => : techb May 31, 2012, 01:42:21 AM
-
With the help of Kulver's index-of and his examples of XChat plug-ins I came up with my own. It is pretty simple and does make my life easier since I have 2 nicks for away and active.
You can find a breif explanation on my blog (http://kbcarte.wordpress.com).
Anyways here's le plugin:
import xchat
__module_name__ = "PyAway"
__module_version__ = "1.0"
__module_description__ = "Changes nick to away, and identifys with the nickserv"
awaynick = "techb_away"
backnick = "techb"
passwrd = "letmein"
def toggleAway(words, words_eol, userdata):
if xchat.get_info("nick") == backnick:
xchat.command("nick %s" % awaynick)
xchat.command("msg nickserv identify %s" % passwrd)
elif xchat.get_info("nick") == awaynick:
xchat.command("nick %s" % backnick)
xchat.command("msg nickserv identify %s" % passwrd)
return xchat.EAT_ALL
xchat.hook_command("away_", toggleAway)
print "Loaded away.py \nUse /away_ to toggle."
The only thing that's not on my blog is the xchat.EAT_ALL. This is to let xchat know not to regard the new command. Else, in the server window, it will show "away_ is an unknown command".
Place in the .xchat2 dir, located in /home/.xchat in linux, and use /py load away.py to load. Anytime you restart it will load automagically. If you don't see .xchat2 in home, hit ctrl+h to see hidden files. Windows users, sorry I don't use windows, but I would imagine its in C:\xchat2\ or C:\[user]\xchat2 or something.
-
Heh
----
To use it on Linux, put it into ~/.xchat2 and it will load every time you start xchat
or you can do it manualy with: /py load voiceall.py
----
To use it on Windows, install Python 2.5
and put it into "X:/Documents and Settings/USERNAME/Application Data/X-Chat 2/"
or you can do it manualy with: /py load voiceall.py
----
http://newage.ql.lt/projects/python/voiceall.py
Not a bad script, even I might use it :P
It's always a good idea to throw in exception handling as well, because sometimes something fucks up :P
Another thing I noticed for loading manually - you must escape the chars :D
So if the script is in C:\script.py, in xchat you would would write C:\\script.py.
That bitch gave me big problems until I debugged the cause...
-
Heh
----
To use it on Linux, put it into ~/.xchat2 and it will load every time you start xchat
or you can do it manualy with: /py load voiceall.py
----
To use it on Windows, install Python 2.5
and put it into "X:/Documents and Settings/USERNAME/Application Data/X-Chat 2/"
or you can do it manualy with: /py load voiceall.py
----
http://newage.ql.lt/projects/python/voiceall.py (http://newage.ql.lt/projects/python/voiceall.py)
Not a bad script, even I might use it :P
It's always a good idea to throw in exception handling as well, because sometimes something fucks up :P
Another thing I noticed for loading manually - you must escape the chars :D
So if the script is in C:\script.py, in xchat you would would write C:\\script.py.
That bitch gave me big problems until I debugged the cause...
I didn't really worry about error handling because it was a quick script meant for me alone. And the only place I can really think of putting an try/except case would be for the imports?
I haven't gotten into hardcore plug-ins, and might switch to C so I can practice.
I didn't know about the escape problem. I always put the plug-ins in the root of XChat, but I suppose you could load from a path like '/py load user@office:~/Desktop/python_code/away.py'
Yeah, python has escape sequence madness, especially when working with system paths.
-
I had to work on this one a bit longer than planned. I had a few bugs with it in the beginning. This new script will change your nick back to what you want. The reason I use it is because for some reason my name gets changed to EvilGuest##### at times.
import xchat
__module_name__ = "PyAutoNick"
__module_version__ = "1.0"
__module_description__ = "Change nick if not yourself and identify. Default check rate is 5 minutes."
rehook = None
def changeTime(words, words_eol, userdata):
global rehook
try:
minutes = int(words[1])*60*1000
except:
print "Invalid argument.\nUsage: /autonick [time in min]"
xchat.unhook(rehook)
rehook = xchat.hook_timer(minutes, checkNick)
def checkNick(userdata):
if xchat.get_info("nick") != "techb" and xchat.get_info("nick") != "techb_away":
xchat.command("nick techb_away")
xchat.command("msg nickserv identify elohelz")
return xchat.EAT_ALL
#300000 == 5 min
rehook = xchat.hook_timer(300000, checkNick)
xchat.hook_command("autonick", changeTime)
The bugs seem to be worked out.