#!/usr/bin/python """IRC bot shell using IRC Async. Sean B. Palmer, 2002. GPL 2. (thanks to deltab)""" # Main config stuff NickName = 'spellbot' MyChannel = '#swhack' Port = 6667 # End of main config stuff import ircAsync import os, sys, socket, urllib, asyncore, difflib from ircAsync import PRIVMSG, NOTICE, PING, PONG, USER from ircAsync import NICK, JOIN, PART, INVITE, QUIT from ircAsync import SPC, CR, LF, CRLF, RPL_WELCOME def ctcp(s): return '\x01%s\x01' % s def me(s): return ctcp('ACTION %s' % s) class AppURLopener(urllib.FancyURLopener): def __init__(self, *args): self.version = "%s/1.0" % NickName apply(urllib.FancyURLopener.__init__, (self,) + args) urllib._urlopener = AppURLopener() WordList = open('./bwords.txt', 'r').read().splitlines() WordList = [word.lower() for word in WordList] WordDict = dict([(key, None) for key in WordList]) def test(hostName, port, chan): c = ircAsync.T() c.startChannels([chan]) c.nick = NickName c.userid = 'blargh' # Put any new functions here def hi(m, origin, args, text, c=c): c.tell(args[1], 'hi, %s' % origin.split('!')[0]) c.bind(hi, PRIVMSG, r"(?i)^(Hi|Hey|welcome)(,)? %s(\!)?$" % NickName) def spell(m, origin, args, text, c=c): result = [] nick = origin.split('!')[0] if nick not in ('d8uv', 'sbp', 'kandinski'): return words = [word.strip(' \t:;\'",.!?') for word in text.split()] words = [word.lower() for word in words if word.isalpha() and len(word) > 5] for word in words: if not WordDict.has_key(word): poss = difflib.get_close_matches(word, WordList, 3, 0.65) poss = [w for w in poss if len(w) < len(word) + 1 and len(w) > len(word) - 1] if poss: result.append('%s could be: %s' % (word, ', '.join(poss))) if result: c.todo([NOTICE, nick], ' :: '.join(result)) c.bind(spell, PRIVMSG, r"^(.*)$") c.makeConn(hostName, port) asyncore.loop() if __name__=='__main__': if len(sys.argv) > 1: MyChannel = sys.argv[1] test('irc.freenode.net', Port, MyChannel)