Christoph Egger schrieb: > I'll do some cleanup of the botscript tomorrow and then place it > somewhere on alioth for Consumption. > > Regards > > Christoph And here it is. IRC Commands are not yet implemented (there are 2 stubs to see how they will work) and it'll need porting to UNIX sockets (should be really easy) but works. Regards Christoph -- /"\ ASCII Ribbon : GPG-Key ID: 0x0372275D \ / Campaign : X against HTML : Working for Debian / \ in eMails : http://www.debian.org/ http://www.christoph-egger.org/
#!/usr/bin/python # Copyright (C) 2009 Christoph Egger # # This software is provided 'as-is', without any express or implied # warranty. In no event will the authors be held liable for any damages # arising from the use of this software. # # Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: # # 1. The origin of this software must not be misrepresented; you must not # claim that you wrote the original software. If you use this software # in a product, an acknowledgment in the product documentation would be # appreciated but is not required. # 2. Altered source versions must be plainly marked as such, and must not be # misrepresented as being the original software. # 3. This notice may not be removed or altered from any source distribution. import irclib from ircbot import SingleServerIRCBot import sys import socket #IRC side network = 'irc.oftc.net' nickname = 'GamesPartyBOT' channel = '#debian-games-party' #Webfrontend side host = '' port = 2222 class GamesPartyBot(SingleServerIRCBot): def __init__(self): SingleServerIRCBot.__init__(self, [(network, 6667)], nickname, nickname) self.queue = ['Hi all!'] self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.socket.bind((host, port)) self.socket.listen(5) self.socket.settimeout(5.0) self.werein = False def run(self): self._connect() while not self.werein: self.ircobj.process_once() while True: self.check_for_data() self.send_out_news() self.ircobj.process_once() def command(self,what,who): try: command,params = what.split(' ', 1) except ValueError: command,params = what,'' m = "command_%s" % command if hasattr(self, m): getattr(self, m)(params,who) else: self.connection.privmsg(channel, 'No idea, honestly') def check_for_data(self): try: readsock,addr = self.socket.accept() except socket.timeout: return blocks = 0 new = "" while True: blocks += 1 if blocks > 5: return newdata = readsock.recv(1024) if len(newdata) == 0: break else: new += newdata if new == 'quit\n': self.connection.quit('DONE') self.ircobj.process_forever() #Make sure everything's flushed out return else: self.queue += new.split('\n') def send_out_news(self): while len(self.queue): item = self.queue.pop() if item != '': self.connection.privmsg(channel, item) def on_welcome(self, connection, event): print 'connected' connection.join(channel) def on_join(self, connection, event): print "I'm now in the channel!" self.werein = True def on_pubmsg(self, connection, event): data = event.arguments()[0] try: if data[0] == '!': self.command(data[1:], event.source().split('!')[0]) elif data[:len(nickname)] == nickname: self.command(data[len(nickname) + 1:].strip(), event.source().split('!')[0]) except ValueError: self.connection.privmsg(channel, 'You do confues me') def on_disconnect(self, connection, event): sys.exit(0) def command_claim(self, params, who): package, comment = params.split(' ', 1) self.connection.privmsg(channel, 'I should now make sure %s is claimed for %s with comment "%s"' % (package, who, comment)) def command_release(self,params,who): self.connection.privmsg(channel, 'I should now clear the claim of %s for %s' % (who, params)) def command_help(self, params, who): if len(params) == 0: message = '!claim, !release' if params in ('!claim', 'claim'): message = '!claim <package> <comment> : Claims the package for you' if params in ('!release', 'release'): message = '!release <package> : Release your claim on the package' self.connection.privmsg(channel, message) if __name__ == '__main__': bot = GamesPartyBot() bot.run()
Attachment:
signature.asc
Description: OpenPGP digital signature