spacepaste

  1.  
  2. from random import randint
  3. import socket
  4. # This is to identify your user/pass to the IRC server so your bot can be masked
  5. # Thought it was safer to have it on user input rather than hardcoded
  6. # user is important cause it gives only the user control of the bot
  7. user = raw_input("enter user ")
  8. secret = raw_input("enter password ")
  9. # name of the bot, channel and irc network
  10. botnick = raw_input("BOT NICKNAME ")
  11. channel = raw_input("IRC CHANNEL ")
  12. network = 'irc.freenode.net'
  13. # irc protocol
  14. port = 6667
  15. irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  16. irc.connect((network, port))
  17. print irc.recv(4096)
  18. # bot will identify to the IRC server and join desired channel
  19. irc.send('NICK ' + botnick + '\r\n')
  20. irc.send('USER vitebot vitebot vitebot:Python IRC\r\n')
  21. irc.send('nickserv identify ' + user + ' ' + secret+ '\r\n')
  22. irc.send('JOIN '+ channel +'\r\n')
  23. irc.send('PRIVMSG '+ channel +' :Hello World.\r\n')
  24. class Nick:
  25. def __init__(self, nick = 0):
  26. self.nick = nick
  27. class Hero:
  28. def __init__(self, hp= 100, money = 0, cash = 100):
  29. self.hp = hp
  30. self.money = money
  31. self.cash = cash
  32. def eat(self):
  33. self.hp = self.hp + 1
  34. def move(self):
  35. self.move = move
  36. class Bad:
  37. def __init__(self, hp = 100):
  38. self.hp = hp
  39. class FIGHT:
  40. def badattack():
  41. x = randint(0, 20)
  42. hero.hp -= x
  43. def heroattack():
  44. y = randint(0, 20)
  45. print "Hero scores %s " % y
  46. bad.hp -= y
  47. # Creating shortcut variables
  48. data = irc.recv(4096)
  49. find = data.find
  50. send = irc.send
  51. attack = FIGHT()
  52. hero = Hero()
  53. bad = Bad()
  54. move = hero.move
  55. nick = Nick.nick
  56. # game script
  57. def dorado():
  58. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  59. send('PRIVMSG ' + nick + " : You have reached dorado\r\n")
  60. options()
  61. def albrook():
  62. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  63. send('PRIVMSG ' + nick + " : You have reached albrook\r\n")
  64. options()
  65. def multiplaza():
  66. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  67. send('PRIVMSG ' + nick + " : You have reached multiplaza\r\n")
  68. options()
  69. def calidonia():
  70. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  71. send('PRIVMSG ' + nick + " : You have reached calidonia\r\n")
  72. options()
  73. def cintacostera():
  74. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  75. send('PRIVMSG ' + nick + " : You have reached cinta costera\r\n")
  76. options()
  77. def panamaviejo():
  78. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money
  79. send('PRIVMSG ' + nick + " : You have reached Panama Viejo\r\n")
  80. options()
  81. def engine():
  82. send('PRIVMSG ' + nick + " : Where to\r\n")
  83. if move == "dorado":
  84. dorado()
  85. elif move == "albrook":
  86. albrook()
  87. elif move == "multiplaza":
  88. multiplaza()
  89. elif move == "calidonia":
  90. calidonia()
  91. elif move == "cinta costera":
  92. cintacostera()
  93. elif move == "panama viejo":
  94. panamaviejo()
  95. else:
  96. send('PRIVMSG ' + nick + " : For money type atm To move type travel available destinations are: dorado\\albrook\\multiplaza\\calidonia\\cinta costera\\panama viejo\r\n"
  97. if hero.hp == 0:
  98. print "YOU ARE DEAD"
  99. def options():
  100. while True:
  101. send('PRIVMSG ' + nick + " : !stats, !atm or !travel> ")
  102. move = find
  103. if move == ":!travel":
  104. if hero.money <= 0:
  105. send('PRIVMSG ' + nick + " : You don't have any money\r\n)
  106. else:
  107. engine()
  108. if move == ":!stats":
  109. send " You have %s money and %s life\n" % (hero.money, hero.hp)
  110. elif move == ":!atm":
  111. hero.money += hero.cash
  112. hero.cash = 0
  113. send('PRIVMSG ' + nick + " : You now have %s money\r\n" % hero.money)
  114. if move == ":!end":
  115. send('PRIVMSG ' + nick + " : Thanks for playing Good BYE\r\n")
  116. elif hero.hp <= 0:
  117. send('PRIVMSG ' + nick + " : GAME OVER YOU HAVE NO MORE LIFE\r\n")
  118. def gamestart()
  119. send('PRIVMSG ' + nick + """ : You have arrived at the Tocumen airport You are a backpacker but here you are THE MOCHILERO You have no cash You see an ATM You also notice you can travel to another place But there fee is $50 to any of the locations\r\n"""
  120. options()
  121. # IRC LOOP
  122. while True:
  123. print data
  124. # This fetches the nicks
  125. nick = data.split('!')[0]
  126. nick = nick.replace(':', ' ')
  127. nick = nick.replace(' ', '')
  128. nick = nick.strip(' \t\n\r')
  129. # PING PONG with the IRC server to avoid getting booted
  130. if find('PING') != -1:
  131. send('PONG ' + data.split()[1] + '\r\n')
  132. print "PONG SENT"
  133. print data
  134. /vite PRIVMSG ptyticker :
  135. # Establishing bot behaviour
  136. elif find('!gamestart'):
  137. gamestart()
  138. elif find(':!quit') != -1:
  139. if user == nick:
  140. send(' PRIVMSG ' + channel + ': Good Bye')
  141. send('quit\r\n')
  142. print data
  143. quit()
  144. # ERROR ####
  145. ### File "ircgame.py", line 100
  146. ### send('PRIVMSG ' + nick + " : You have reached Panama Viejo\r\n")
  147.