rory
T^T
This is a project I have been working on for quite a while now and I am very glad to say that it is more or less finished. What inspired this was creating a "BaseBot" for #stark that would help people out spitting out information and doing calculations. As it progressed I decided I wanted to clean it up and write a framework in python that would make it easy to add on to the Uxie (the basebot) and maintain clean code. I haven't written Uxie in the framework yet, since I haven't bothered to write my pokemon data package yet, but I'm still releasing this framework.
It is, as far as I know, the only event based IRC framework for python3.
The files for the project and all the source code can be found here.
An example of the simplicity of this framework is as follows:
The project is now created. As you can see the make_project function created a packages folder, a run.py file, and a settings.py file.
I then went and created a file in the packages folder called uxie.py and wrote the following in it:
and settings.py (most of which was already there):
Then all i need to do is:
and uxie runs with the following output:
As you can see at the end of the log, Uxie responds to the handler I just wrote.
In the near future I plan to do the following:
It is, as far as I know, the only event based IRC framework for python3.
The files for the project and all the source code can be found here.
An example of the simplicity of this framework is as follows:
Code:
[rory@localhost ~]$ python3
Python 3.1.1 (r311:74480, Aug 24 2009, 15:50:43)
[GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pierce.irc import make_project
>>> make_project('uxie')
>>>
[rory@localhost ~]$ cd uxie
[rory@localhost uxie]$ ls
packages run.py settings.py
I then went and created a file in the packages folder called uxie.py and wrote the following in it:
Code:
import re
from pierce.irc.templates import Handler, Package
class MyHandler(Handler):
# have the handler respond to messages
event = ['privmsg']
# only on the channel #rorytest!
chan = ['#rorytest']
# Any message must match the following regexp for the handler to be called
regexp = [re.compile('(Uxie: )?What do you do?', re.IGNORECASE)]
# what to do when the handler is called
def __call__(self, event):
# message the event channel
event.chan.msg("I don't do shit yet!")
# a package with my handler in it
class Uxie(Package):
contents = [ MyHandler ]
Code:
# Server and port to connect to
server = 'irc.synirc.net'
port = 6667
# Nick, user, and realname to connect with
# Leave user None to use the same nick and username
nick = 'Uxie'
user = None
realname = 'A Pierce IRC Bot'
# Packages to add to the connection
from packages.uxie import Uxie # importing the package I just created
from pierce.irc.packages.printer import Printer
from pierce.irc.packages.extras import AutoIdentify
packages = [ Uxie, Printer, AutoIdentify ] # all packages here will be added
# Channels to automatically join on connection
auto_join = ['#rorytest']
# Passwords for specific nicks
passwords = {'uxie': 'XXXXXXXX'}
Code:
[rory@localhost uxie]$ python3 run.py connect
Code:
[20:43:23] >> USER Uxie Uxie Uxie :A Pierce IRC Bot
[20:43:23] >> NICK Uxie
[20:43:23] {AUTH} -avarice.az.us.synirc.net - *** Looking up your hostname...
[20:43:23] {AUTH} -avarice.az.us.synirc.net - *** Checking ident...
[20:43:23] {AUTH} -avarice.az.us.synirc.net - *** No ident response; username prefixed with ~
[20:43:24] {AUTH} -avarice.az.us.synirc.net - *** Couldn't resolve your hostname; using your IP address instead
[20:43:24] << Welcome to the synIRC IRC Network Uxie!~Uxie@12.24.38.132
[20:43:24] << Your host is avarice.az.us.synirc.net, running version Unreal3.2.6
[20:43:24] << This server was created Tue Jul 17 2007 at 10:16:41 GMT
[20:43:24] << avarice.az.us.synirc.net Unreal3.2.6 iowghraAsORTVSxNCWqBzvdHtGp lvhopsmntikrRcaqOALQbSeIKVfMCuzNTGj
[20:43:24] << CMDS=KNOCK,MAP,DCCALLOW,USERIP NAMESX SAFELIST HCN MAXCHANNELS=20 CHANLIMIT=#:20 MAXLIST=b:60,e:60,I:60 NICKLEN=30 CHANNELLEN=32 TOPICLEN=307 KICKLEN=307 AWAYLEN=307 MAXTARGETS=20 :are supported by this server
[20:43:24] << WALLCHOPS WATCH=128 SILENCE=15 MODES=12 CHANTYPES=# PREFIX=(qaohv)~&@%+ CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG NETWORK=synIRC CASEMAPPING=ascii EXTBAN=~,cqnr ELIST=MNUCT STATUSMSG=~&@%+ EXCEPTS :are supported by this server
[20:43:24] << INVEX :are supported by this server
[20:43:24] << There are 39 users and 5131 invisible on 12 servers
[20:43:24] << 31 :operator(s) online
[20:43:24] << 1354 :channels formed
[20:43:24] << I have 741 clients and 0 servers
[20:43:24] << Current Local Users: 741 Max: 1005
[20:43:24] << Current Global Users: 5170 Max: 6288
[20:43:24] << - avarice.az.us.synirc.net Message of the Day -
[20:43:24] << - 28/11/2008 22:10
[20:43:24] << - ___ ____ ____
[20:43:24] << - ___ _ _ _ __ |_ _| _ \ / ___|
[20:43:24] << - / __| | | | '_ \ | || |_) | |
[20:43:24] << - \__ \ |_| | | | || || _ <| |___
[20:43:24] << - |___/\__, |_| |_|___|_| \_\\____|
[20:43:24] << - |___/ Phoenix, AZ, USA
[20:43:24] << -
[20:43:24] << - Server : avarice.az.us.synirc.net
[20:43:24] << - Ports : 6660-9, 7000
[20:43:24] << - SSL Ports : 7001, 8000
[20:43:24] << - Admin : Sony (sony@synirc.net)
[20:43:24] << - Coadmin : Special (special@synirc.net)
[20:43:24] << - IRCop : Josh (josh@synirc.net)
[20:43:24] << - : Pak000 (pak000@synirc.net)
[20:43:24] << -
[20:43:24] << - Please visit us online at http://www.synirc.net/
[20:43:24] << - For network related assistance please join #Help
[20:43:24] << - For network wide bans and other issues email helpcom@synirc.net
[20:43:24] << -
[20:43:24] << - synIRC.net will scan your IP for open proxies upon connection to our
[20:43:24] << - services. You must be 18 or older to connect and chat on our services, or
[20:43:24] << - have parental consent. synIRC.net and its affiliates are not responsible
[20:43:24] << - for any bodily or mental harm that could possibly come from using its
[20:43:24] << - services. synIRC.net is not responsible for any data received or sent
[20:43:24] << - out to our clients. By connecting, you consent to have logging of your
[20:43:24] << - conversations done by other clients and are also bound to the rules and
[20:43:24] << - regulations that can be found at http://www.synirc.net/charter/
[20:43:24] << End of /MOTD command.
[20:43:24] {Uxie} *** Uxie sets mode +ix
[20:43:24] {Uxie} -Global- [Logon News - Aug 02 2009] Follow synIRC on Twitter! http://twitter.com/synirc
[20:43:24] {Uxie} -NickServ- This nickname is registered and protected. If it is your
[20:43:24] {Uxie} -NickServ- nick, type /msg NickServ IDENTIFY password. Otherwise,
[20:43:24] {NickServ} <Uxie> IDENTIFY XXXXXXXX
[20:43:24] {Uxie} -NickServ- please choose a different nick.
[20:43:24] {Uxie} -NickServ- If you do not change within 20 seconds, I will change your nick.
[20:43:24] {Uxie} *** services.synirc.net sets mode +r
[20:43:24] {Uxie} -NickServ- Password accepted - you are now recognized.
[20:43:24] {Uxie} -NickServ- Automatically joining #rorytest .
[20:43:24] {#rorytest} Uxie has joined #rorytest
[20:43:24] {Uxie} -NickServ- Automatically joining #stark .
[20:43:24] {#stark} Uxie has joined #stark
[20:43:24] {#rorytest} *** ChanServ sets mode +qo Uxie Uxie
[20:43:31] {#stark} <Jibaku> Uxie is back!
[20:43:35] {#stark} <Thorns> ok
[20:43:38] {#stark} <Thorns> time to get to work
[20:43:40] {#stark} <Theorymon> gives me an excuse to use it with Starmie + Kyogre + Ho-oh
[20:43:40] {#stark} <Rory> it doesn't do shit yet
[20:43:49] {#stark} <Rory> it just autojoined all my channels since it's in my group
[20:43:51] {#rorytest} <Rory> hi
[20:44:18] {#rorytest} <Rory> uxie: what do you do?
[20:44:18] {#rorytest} <Uxie> I don't do shit yet!
In the near future I plan to do the following:
- Finish my pokemon data package
- Write Uxie
- Write some fun game bots for #fluodome
- Write logging packages and other extras for the framework
- Make settings.py and run.py a bit better
- Documentation and a tutorial