From 6a89acd2a0318ca7042c00ae027dd7e9d871777d Mon Sep 17 00:00:00 2001 From: yvesf Date: Sat, 12 Dec 2009 14:47:22 +0000 Subject: blah! git-svn-id: http://xapek.org/svn/common/omegle@1482 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- omegle/icqRoombot.py | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 omegle/icqRoombot.py (limited to 'omegle/icqRoombot.py') diff --git a/omegle/icqRoombot.py b/omegle/icqRoombot.py new file mode 100644 index 0000000..2ded976 --- /dev/null +++ b/omegle/icqRoombot.py @@ -0,0 +1,120 @@ +#!/usr/bin/python +# Yves Fischer, xapek.org 2009 + +import sys +from icq import ExtendedBOSConnection, ReconnectOscarFactory, Authenticator +from random import randint +from twisted.python import log +from twisted.internet import reactor + +class Member(object): + def __init__(self,id,name): + self.id = id + self.name = name + +class Room(object): + def __init__(self): + self.members = [] + self.msg_cbs = [] + + def addMessageCallback(self,cb): + self.msg_cbs.append(cb) + + def removeMessageCallback(self,cb): + self.msg_cbs.remove(cb) + + def join(self,member): + self.members.append(member) + + def leave(self,member): + self.members.remove(member) + + def getMemberById(self,id): + l=filter(lambda member: member.id == id, self.members) + if len(l) > 0: + return l[0] + else: + return None + + instance = None + @classmethod + def getInstance(klass): + if klass.instance == None: + klass.instance = Room() + return klass.instance + +CAP_TYPING = '\x56\x3f\xc8\x09\x0b\x6f\x41\xbd\x9f\x79\x42\x26\x09\xdf\xa2\xf3' +class ICQRoombot( ExtendedBOSConnection ): + + def initDone( self ): + ExtendedBOSConnection.initDone(self) + self.room = Room.getInstance() + self.members = dict() + + def receiveCleanMessage( self, user, message, flags ): + print "receiveCleanMessage" + try: + if self.room.getMemberById(user.name) != None: + member = self.room.getMemberById(user.name) + + if message.strip() == "/leave": + self.room.leave(member) + self.sendMessage(user.name, 'You left') + for otherMember in self.room.members: + self.sendMessage(otherMember.id, "===== %s/%s left"%(member.name,member.id) ) + elif message.strip().startswith("/invite"): + otherUin = message.strip().split("/invite")[1].strip() + self.sendMessage(otherUin, "Youre invited by %s to join this room!, Type \" /join nickname\""%(user.name)) + self.sendMessage(member.id, "Invitation sent to %s"%otherUin) + elif message.strip().startswith("/nick"): + newNick = message.strip().split("/nick")[1] + for otherMember in self.room.members: + self.sendMessage(otherMember.id, "===== %s now known as %s" % (member.name,newNick)) + member.name = newNick + elif message.strip().startswith("/msg"): + otherNick = message.strip().split("/msg")[1].strip().split(" ")[0] + otherMember = filter(lambda m: m.name == otherNick, self.room.members) + if len(otherMember) == 0: + self.sendMessage(member.id, "===== Nick %s gibts nicht!" % otherNick) + else: + self.sendMessage(otherMember[0].id, "=== Privat von %s/%s: %s" % (member.name,member.id,message)) + elif message.strip() == "/list": + self.sendMessage(member.id, "===== List: %s"%", ".join(map(lambda m: "%s/%s"%(m.id,m.name),self.room.members)) ) + elif message.strip().startswith("/"): + self.sendMessage(member.id, "===== kennich nicht") + else: + i=0 + for otherMember in self.room.members: + i += 1 + if otherMember.id == user.name: + continue + reactor.callLater(i, self.sendMessage, otherMember.id, "%s: %s" %(member.name, message.strip())) + else: + if message.strip().startswith("/join"): + nick = message.strip().split("/join")[1].strip() + member = Member(user.name, nick) + self.room.join(member) + i=0 + for otherMember in self.room.members: + i += 1 + reactor.callLater(i, self.sendMessage, otherMember.id, "===== %s/%s joined" % (member.name,member.id)) + else: + if randint(0,5) == 3: + self.sendMessage(user.name, "Use '/join Nickname' or ' /join Nickname'") + + self.sendAuthorizationResponse(user.name, True, '') + except Exception,e: + print "error: %s %s\n%s" % (user,multiparts,e) + +if __name__ == '__main__': + uin = '370496181' + password = 'megahal123' + host, port = ('login.oscar.aol.com', 5190) + + import logging + logging.basicConfig(level=logging.INFO) + log.startLogging(sys.stdout) + + fac = ReconnectOscarFactory(ICQRoombot, uin, password, icq=1) + reactor.connectTCP(host, port, fac) + reactor.run() -- cgit v1.2.1