# UIN UIN = "" # PASS = "" # host = ( "login.icq.com" , 5238) # / icqMode = 1 # Status message AMSG = "I'm here +)" * This source code was highlighted with Source Code Highlighter .
# UIN UIN = "" # PASS = "" # host = ( "login.icq.com" , 5238) # / icqMode = 1 # Status message AMSG = "I'm here +)" * This source code was highlighted with Source Code Highlighter .
# UIN UIN = "" # PASS = "" # host = ( "login.icq.com" , 5238) # / icqMode = 1 # Status message AMSG = "I'm here +)" * This source code was highlighted with Source Code Highlighter .
# UIN UIN = "" # PASS = "" # host = ( "login.icq.com" , 5238) # / icqMode = 1 # Status message AMSG = "I'm here +)" * This source code was highlighted with Source Code Highlighter .
# UIN UIN = "" # PASS = "" # host = ( "login.icq.com" , 5238) # / icqMode = 1 # Status message AMSG = "I'm here +)" * This source code was highlighted with Source Code Highlighter .
# UIN UIN = "" # PASS = "" # host = ( "login.icq.com" , 5238) # / icqMode = 1 # Status message AMSG = "I'm here +)" * This source code was highlighted with Source Code Highlighter .
# UIN UIN = "" # PASS = "" # host = ( "login.icq.com" , 5238) # / icqMode = 1 # Status message AMSG = "I'm here +)" * This source code was highlighted with Source Code Highlighter .
# UIN UIN = "" # PASS = "" # host = ( "login.icq.com" , 5238) # / icqMode = 1 # Status message AMSG = "I'm here +)" * This source code was highlighted with Source Code Highlighter .
# UIN UIN = "" # PASS = "" # host = ( "login.icq.com" , 5238) # / icqMode = 1 # Status message AMSG = "I'm here +)" * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- from twisted.words.protocols import oscar
- from twisted.internet import protocol, reactor
- import feedparser
- import urllib2 # Please do not bother with this. For what it is, I'll tell you later
* This source code was highlighted with Source Code Highlighter .
- # Class Bot
- class Bot (oscar.BOSConnection):
- capabilities = [oscar.CAP_CHAT]
- def initDone (self):
- print "Connect" , UIN, "to server" , host [0], host [1]
- self.requestSelfInfo (). addCallback (self.gotSelfInfo)
- self.requestSSI (). addCallback (self.gotBuddyList)
- self.setAway (AMSG)
- def gotSelfInfo (self, user):
- print user .__ dict__
- self.name = user.name
- def gotBuddyList (self, l):
- print l
- self.activateSSI ()
- self.setProfile ( "" "ICQBot" "" )
- self.setIdleTime (0)
- self.clientReady ()
- def gotAway (self, away, user):
- if away:
- print "User" , user, ":" , away
* This source code was highlighted with Source Code Highlighter .
- def receiveMessage (self, user, multiparts, flags):
- print "\ n <From:" , user.name
- print "<Message:" , multiparts [0] [0] .decode ( 'cp1251' )
- command = multiparts [0] [0] .lower (). split ( '' ) # split the message by spaces
- PREF_C = "!" # teams will start with us!
* This source code was highlighted with Source Code Highlighter .
- if command [0] == (PREF_C + "habr" ):
- rss = feedparser.parse ( 'http://habrahabr.ru/rss' ) # pick up the xml page and parsim
- feeds = [0.20] # This is for additional functionality here)
- if len (command) == 2:
- try :
- feeds [1] = int (command [1])
- except:
- feeds [1] = 0
- if feeds [1] <1: feeds [1] = 1
- if feeds [1]> 20: feeds [1] = 20
- elif len (command) == 3:
- try :
- feeds [0] = int (command [1]) - 1
- feeds [1] = int (command [2])
- except:
- feeds [0] = 0
- feeds [1] = 19
- if feeds [0] <0: feeds [0] = 0
- if feeds [0]> 19: feeds [0] = 19
- if feeds [1] <1: feeds [1] = 1
- if feeds [1]> 20: feeds [1] = 20
- mes = ''
- for feed in range (feeds [0], feeds [1]):
- mes + = rss.entries [feed] .title + '\ n'
- self.sendMessage (user.name, mes)
* This source code was highlighted with Source Code Highlighter .
- elif command [0] == (PREF_C + "habrn" ):
- rss = feedparser.parse ( 'http://habrahabr.ru/rss' )
- try :
- feedn = int (command [1]) - 1
- except:
- feedn = 0
- if feedn <0: feedn = 0
- if feedn> 19: feedn = 19
- self.sendMessage (user.name, rss.entries [feedn] .title + '\ n' + rss.entries [feedn] .description)
* This source code was highlighted with Source Code Highlighter .
- elif command [0] == (PREF_C + "ip" ) and user.name == '368576236' :
- file_s = urllib2.urlopen (urllib2.Request ( 'http://api.wipmania.com/' ))
- response = file_s.read ()
- self.sendMessage (user.name, response.split ( "<br>" ) [0])
- f.close ()
* This source code was highlighted with Source Code Highlighter .
- class BotAuth (oscar.OscarAuthenticator):
- BOSClass = Bot
- protocol.ClientCreator (reactor, BotAuth, UIN, PASS, icq = icqMode) .connectTCP (* host)
- reactor.run ()
* This source code was highlighted with Source Code Highlighter .
- # - * - coding: utf-8 - * -
- # ICQ bot
- #Uin
- UIN = "123456"
- PASS = "pass"
- # Server
- host = ( "login.icq.com" , 5238)
- icqMode = 1
- # Status message
- AMSG = "I'm here +)"
- from twisted.words.protocols import oscar
- from twisted.internet import protocol, reactor
- import feedparser
- import urllib2
- # Class Bot
- class Bot (oscar.BOSConnection):
- capabilities = [oscar.CAP_CHAT]
- def initDone (self):
- print "Connect" , UIN, "to server" , host [0], host [1]
- self.requestSelfInfo (). addCallback (self.gotSelfInfo)
- self.requestSSI (). addCallback (self.gotBuddyList)
- self.setAway (AMSG)
- def gotSelfInfo (self, user):
- print user .__ dict__
- self.name = user.name
- def gotBuddyList (self, l):
- print l
- self.activateSSI ()
- self.setProfile ( "" "ICQBot" "" )
- self.setIdleTime (0)
- self.clientReady ()
- def gotAway (self, away, user):
- if away:
- print "User" , user, ":" , away
- def receiveMessage (self, user, multiparts, flags):
- print "\ n <From:" , user.name
- print "<Message:" , multiparts [0] [0] .decode ( 'cp1251' )
- command = multiparts [0] [0] .lower (). split ( '' )
- PREF_C = "!"
- if command [0] == (PREF_C + "habr" ):
- rss = feedparser.parse ( 'http://habrahabr.ru/rss' )
- feeds = [0.20]
- if len (command) == 2:
- try :
- feeds [1] = int (command [1])
- except:
- feeds [1] = 0
- if feeds [1] <1: feeds [1] = 1
- if feeds [1]> 20: feeds [1] = 20
- elif len (command) == 3:
- try :
- feeds [0] = int (command [1]) - 1
- feeds [1] = int (command [2])
- except:
- feeds [0] = 0
- feeds [1] = 19
- if feeds [0] <0: feeds [0] = 0
- if feeds [0]> 19: feeds [0] = 19
- if feeds [1] <1: feeds [1] = 1
- if feeds [1]> 20: feeds [1] = 20
- mes = ''
- for feed in range (feeds [0], feeds [1]):
- mes + = rss.entries [feed] .title + '\ n'
- self.sendMessage (user.name, mes)
- elif command [0] == (PREF_C + "habrn" ):
- rss = feedparser.parse ( 'http://habrahabr.ru/rss' )
- try :
- feedn = int (command [1]) - 1
- except:
- feedn = 0
- if feedn <0: feedn = 0
- if feedn> 19: feedn = 19
- self.sendMessage (user.name, rss.entries [feedn] .title + '\ n' + rss.entries [feedn] .description)
- elif command [0] == (PREF_C + "ip" ) and user.name == '123456' :
- file_s = urllib2.urlopen (urllib2.Request ( 'http://api.wipmania.com/' ))
- response = file_s.read ()
- self.sendMessage (user.name, response.split ( " <br> " ) [0])
- f.close ()
- class BotAuth (oscar.OscarAuthenticator):
- BOSClass = Bot
- protocol.ClientCreator (reactor, BotAuth, UIN, PASS, icq = icqMode) .connectTCP (* host)
- reactor.run ()
Source: https://habr.com/ru/post/111263/
All Articles