/new/donna.py

https://bitbucket.org/bumbolt/donna
Python | 69 lines | 50 code | 18 blank | 1 comment | 10 complexity | 1a3a557bed3d449a224c2aebab53c822 MD5 | raw file
  1. import socket
  2. import random
  3. import subprocess
  4. from subprocess import Popen
  5. # Some basic variables used to configure the bot
  6. server = "reinoutclaeys.be" # Server
  7. channel = "#test" # Channel
  8. botnick = "donna" # Your bots nick
  9. def ping(): # This is our first function! It will respond to server Pings.
  10. ircsock.send("PONG :pingis\n")
  11. def sendmsg(chan , msg): # This is the send message function, it simply sends messages to the channel.
  12. ircsock.send("PRIVMSG "+ chan +" :"+ msg +"\n")
  13. def joinchan(chan): # This function is used to join channels.
  14. ircsock.send("JOIN "+ chan +"\n")
  15. def hello(): # This function responds to a user that inputs "Hello Mybot"
  16. ircsock.send("PRIVMSG "+ channel +" :Hello!\n")
  17. def gtfo():
  18. ircsock.send("PRIVMSG "+ channel +" :GTFO!\n")
  19. def restart():
  20. ircsock.send("PRIVMSG "+ channel +" :Niet met mij! Norma eerst!\n")
  21. Popen("python /home/bumbolt/Documents/git-repos/donna/reloader.py", shell=True) # start reloader
  22. exit("exit for updating all files")
  23. def ewout():
  24. numb = random.randint(0,3)
  25. if numb == 0:
  26. ircsock.send("PRIVMSG"+ channel+ " :Niet kijken, Ammoboy!\n")
  27. if numb == 1:
  28. ircsock.send("PRIVMSG"+ channel+ " :Eeeeikes!\n")
  29. if numb == 2:
  30. ircsock.send("PRIVMSG"+ channel+ " :Viezerikken\n")
  31. ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  32. ircsock.connect((server, 6667)) # Here we connect to the server using the port 6667
  33. ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This bot is a result of a tutoral covered on http://shellium.org/wiki.\n") # user authentication
  34. ircsock.send("NICK "+ botnick +"\n") # here we actually assign the nick to the bot
  35. joinchan(channel) # Join the channel using the functions we previously defined
  36. while 1: # Be careful with these! it might send you to an infinite loop
  37. ircmsg = ircsock.recv(2048) # receive data from the server
  38. ircmsg = ircmsg.strip('\n\r') # removing any unnecessary linebreaks.
  39. print(ircmsg) # Here we print what's coming from the server
  40. if ircmsg.find(":Hello "+ botnick) != -1: # If we can find "Hello Mybot" it will call the function hello()
  41. hello()
  42. if ircmsg.find("PING :") != -1: # if the server pings us then we've got to respond!
  43. ping()
  44. if ircmsg.find(":teemo") != -1:
  45. gtfo()
  46. if ircmsg.find(":9gag") != -1:
  47. gtfo()
  48. if ircmsg.find(":sex") != -1:
  49. ewout()
  50. if ircmsg.find(":!restart") != -1:
  51. restart()