comment
IRC Chat
play_arrow
Este sitio utiliza cookies propias y de terceros. Si continúa navegando consideramos que acepta el uso de cookies. OK Más Información.

IRC Bot

  • 0 Respuestas
  • 1527 Vistas

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado @ed33x

  • *
  • Underc0der
  • Mensajes: 107
  • Actividad:
    0%
  • Reputación 0
    • Ver Perfil
    • Email
« en: Enero 30, 2011, 10:11:18 am »
Código: Python
  1. #!/usr/bin/env python
  2.  
  3. # This is a just for fun experiment bot to learn how IRC works
  4. # My name is Andre and I go by the handle Tr1pX
  5. # Feel free to contact me floridait[--at--]gmail[---dot---]com
  6. # This bot was tested on irc.bluehell.org
  7.  
  8. import sys
  9. import socket
  10. import string
  11. import time
  12. import os # when I use this import in linux it works but you might have to change it for winblows
  13.  
  14. # here are our connection variables
  15. HOST="irc.bluehell.org"
  16. PORT=6667
  17. REALNAME="Ceasar"
  18. # the readbuffer stores all the data the server send to us
  19. readbuffer=""
  20. # here we give the bot a name
  21. try:
  22. nickname = sys.argv[1]
  23.  
  24. print "[+] Joining with name "+nickname
  25. except IndexError:
  26. print '-This bot is designed for BlueHell-'
  27. print '-----Please use xbot.py <nick>-----'
  28. sys.exit()
  29.  
  30. CHAN='#bhf'
  31. NICK=nickname
  32. IDENT=NICK
  33. # here we connect to the irc server
  34. s=socket.socket( )
  35. s.connect((HOST, PORT))
  36. s.send("NICK %s\r\n" % NICK)
  37. s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
  38. # here are some other variables that we need to set
  39. BOTOWNER = 'Tr1pX'
  40. things_to_say = ['Here\'s 20 cents. Call all your friends and bring back some change! ',
  41. 'Any similarity between you and a human is purely coincidental! ',
  42. 'Calling you stupid would be an insult to stupid people. ',
  43. 'Do you ever wonder what life would be like if you\'d had enough oxygen at birth? ',
  44. 'Do you want people to accept you as you are or do you want them to like you? ',
  45. 'Do you still love nature, despite what it did to you? ',
  46. 'Don\'t you need a license to be that ugly? ',
  47. 'Every person has the right to be ugly, but you abused the privilege! ',
  48. 'You are the kind of a man that you would use as a blueprint to build an idiot. ']
  49. #here goes our functioning part
  50.  
  51.  
  52. def ai (tmp):
  53. msgstrip = tmp.rstrip().split(' ', 3) # seperate the message text from the rest
  54. msgtrigger = msgstrip[3]
  55. sender = msgstrip[0].strip(':').split('!')[0] #here we get the command givers name
  56.  
  57. # now we define what happens if we get certain words
  58. if msgstrip[1] == "PRIVMSG" and msgstrip[2] == CHAN or NICK:
  59. if msgtrigger == ':'+NICK+':':
  60. print "[+] %s mentioned your name!" % sender #this is for output to the console the bot is running in
  61. the_msg = ' I am busy right now! I\'ll brb '+sender
  62. msg_sender(CHAN, the_msg) # remeber to put CHAN in there for the destination
  63.  
  64. if msgtrigger == ':lol':
  65. print "[+] %s typed a known trigger" % sender
  66. the_msg1 = sender+' is laughing out loud!'
  67. msg_sender(CHAN, the_msg1) # remeber to put CHAN in there for the destination
  68.  
  69. if msgtrigger == ':hmm':
  70. print "[+] %s typed a known trigger" % sender
  71. the_msg2 = 'What are you thinking about so hard '+sender+'?'
  72. msg_sender(CHAN, the_msg2) # remeber to put CHAN in there for the destination
  73.  
  74. if msgtrigger == ':hello':
  75. print "[+] %s typed a known trigger" % sender
  76. the_msg3 = 'Hello '+sender+'!'
  77. msg_sender(CHAN, the_msg3) # remeber to put CHAN in there for the destination
  78.  
  79. if msgtrigger == ':lmao':
  80. print "[+] %s typed a known trigger" % sender
  81. the_msg5 = sender+' is laughing his a$$ off!'
  82. msg_sender(CHAN, the_msg5)
  83.  
  84. # here we are going to write more functional commands
  85. if msgtrigger == ':!change.name':
  86. print "[+] %s gave the command to change the name" % sender
  87. the_msg6 = 'OK! '+sender+', I will change my name now.'
  88. msg_sender(CHAN, the_msg6)
  89. recon_newnick(CHAN, sender)
  90.  
  91. if msgtrigger == ':!exit':
  92. print "[+] %s gave me the command to exit" % sender
  93. the_msg7 = 'OK! '+sender+', let me check if you have permission to turn me off.'
  94. msg_sender(CHAN, the_msg7)
  95. permission(CHAN, sender)
  96.  
  97. if msgtrigger == ':!commands':
  98. print "[+] %s has requested a list of commands" % sender
  99. the_msg8 = 'OK! '+sender+', here come my commands:'
  100. msg_commands = '[1] !change.name [2] !commands [3] !exit [4] !op.me [5] !diss.me [#] More to come: '+sender
  101. msg_sender(CHAN, the_msg8)
  102. msg_sender(CHAN, msg_commands)
  103.  
  104. if msgtrigger == ':!op.me':
  105. print "[+] %s wants me to give him op" % sender
  106. the_msg9 = 'OK! '+sender+', let me see if I can give you Op status.'
  107. msg_sender(CHAN, the_msg9)
  108. give_op(CHAN, sender)
  109.  
  110. if msgtrigger == ':!diss.me':
  111. print "[+] %s typed a known trigger" % sender
  112. the_msg10 = 'Ok! '+sender+' the following apply to you!'
  113. msg_sender(CHAN, the_msg10)
  114. x = 0
  115. for text in things_to_say:
  116. x = x + 1
  117. text = str(x) + '. ' + text
  118. time.sleep(3)
  119. msg_sender(CHAN, text)
  120.  
  121. # if msgtrigger == ':!create.army':
  122. # print "[+] %s is trying to load more bots" % sender
  123. # the_msg11 = 'OK! '+sender+', I am getting back-up now, are you sure? ~(!create.army!yes / !create.army!no)~'
  124. # msg_sender(CHAN, the_msg11)
  125. #
  126. # if msgtrigger == ':!create.army!yes':
  127. # print "[+] %s has confirmed that he wants more bots" % sender
  128. # msg_yes = 'Ok! '+sender+', as you wish!'
  129. # msg_sender(CHAN, msg_yes)
  130. # more_bots()
  131. #
  132. # if msgtrigger == ':!create.army!no':
  133. # print "[+] %s has canceled and wants no more bots"
  134. # msg_no = 'OK! '+sender+', I have cancelled your request'
  135. # msg_sender(CHAN, msg_no)
  136.  
  137. #def more_bots (): # this function does work but most irc servers have a host session limit
  138. # b = 0 # so after 3 connects from one host they will be created but the old ones disconnect
  139. # while b < 5: # here you can set the number of bots to enter
  140. # time.sleep(5)
  141. # b = b + 1
  142. # os.popen('python soldier.py soldier'+str(cool.gif) # i dont know if this works in windows but it does in linux
  143.  
  144.  
  145.  
  146. def give_op (channel, commander): # this function allows the bot to give the botowner op only if
  147. if commander == BOTOWNER: # the bot has op status though obviously
  148. print "[+] %s is recordnized as a authorized user" % commander
  149. s.send("MODE "+channel+' +o '+commander+'\r\n')
  150. op_msg = commander+', if I had the power to OP you, then you should be OP now!'
  151. msg_sender(channel, op_msg)
  152. time.sleep(5) # most of these sleep commands just keep the bot from flooding
  153. commander = ''
  154.  
  155. elif commander != BOTOWNER:
  156. print "[+] %s has no authority for OP" % commander
  157. denied_op_msg = 'I am sorry '+commander+', but you don\'t have permission to be OPed'
  158. msg_sender(channel, denied_op_msg)
  159. time.sleep(5)
  160. commander = ''
  161.  
  162.  
  163.  
  164. def permission (channel, commander): # this function is to shut the bot down with !exit, it checks your nick
  165. if commander == BOTOWNER : # or botowner variable to see if the commander is authorized
  166. print "[+] Shutting down connection"
  167. shutdown_msg = '[+]Shutting Down[+] Good Bye '+commander+'!'
  168. msg_sender(channel, shutdown_msg)
  169. s.send("PART \r\n")
  170. time.sleep(5)
  171. sys.exit()
  172.  
  173. elif commander != BOTOWNER:
  174. print "[+] %s has no proper authority!" % commander
  175. denied_msg = '[+]Shut down denied[+] '+commander+' has no authority!'
  176. msg_sender(channel, denied_msg)
  177. time.sleep(5)
  178. commander = ''
  179.  
  180.  
  181. def recon_newnick (channel, commander): # this function lets you command the bot to change its name to yournicks_p3t
  182. s.send("PART \r\n")
  183. s.send("NICK "+commander+'s_p3t \r\n')
  184. s.send("JOIN "+channel+'\r\n')
  185.  
  186. time.sleep(10)
  187. confirm_msg = 'I changed my name '+commander+', like you wanted me to.'
  188. msg_sender(channel, confirm_msg)
  189.  
  190. commander = '' # we have to clear commander to avoid errors like wrong sender or multiple
  191.  
  192.  
  193. def msg_sender (destination, message): # this is the communicator, it sends all messages to irc for processing
  194. s.send("PRIVMSG "+destination+" :"+message+"\r\n")
  195. time.sleep(5)
  196. message = '' # we have to make sure that message is empty before getting another trigger
  197.  
  198. def connect_to_channel (check): # I wrote this function to make the bot run smoother by not always running the same
  199. try: # loop over and over trying to connect to the same channel
  200. connected = check.rstrip().split(' ', 3)
  201. are_we_con = connected[2]
  202. if are_we_con != CHAN: # check to see if we already joined the channel
  203. s.send('JOIN '+CHAN+'\r\n') #here we connect to the channel
  204. except IndexError:
  205. print "[+] Ideling"
  206. #here ends our function
  207.  
  208. while 1: # this is our connection loop
  209. readbuffer=readbuffer+s.recv(1024) # here we get data no more than 1024 bytes
  210. chan_check = readbuffer # here i set up a test variable to search for data
  211. connect_to_channel(chan_check) # here i call my connection function
  212. if readbuffer.find('PRIVMSG') != -1: # here we get the data ready for processing for the ai() function
  213. ai(chan_check) # this sends all data to the ai() function so it recorgnizes the triggers
  214. temp=string.split(readbuffer, "\n")
  215. readbuffer=temp.pop( ) # remove our last line to get room for the next
  216. for line in temp:
  217. line=string.rstrip(line)
  218. line=string.split(line)
  219. print "[+] %s" % line # this line helps me right my other function to see some output
  220.  
  221. if(line[0]=="PING"): # every bot needs to tell IRC that they are alive here
  222. s.send("PONG %s\r\n" % line[1])
  223.  
« Última modificación: Enero 18, 2013, 05:33:05 pm por 11Sep »
Me cambie de messenger ahora es: edeex@live.comNo tienes permisos para ver links. Registrate o Entra con tu cuenta

 

¿Te gustó el post? COMPARTILO!