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. temp = Nick()
  56. nick = temp.nick
  57. # game script
  58. def dorado():
  59. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  60. send('PRIVMSG ' + nick + " : You have reached dorado\r\n")
  61. options()
  62. def albrook():
  63. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  64. send('PRIVMSG ' + nick + " : You have reached albrook\r\n")
  65. options()
  66. def multiplaza():
  67. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  68. send('PRIVMSG ' + nick + " : You have reached multiplaza\r\n")
  69. options()
  70. def calidonia():
  71. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  72. send('PRIVMSG ' + nick + " : You have reached calidonia\r\n")
  73. options()
  74. def cintacostera():
  75. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  76. send('PRIVMSG ' + nick + " : You have reached cinta costera\r\n")
  77. options()
  78. def panamaviejo():
  79. send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
  80. send('PRIVMSG ' + nick + " : You have reached Panama Viejo\r\n")
  81. options()
  82. def engine():
  83. send('PRIVMSG ' + nick + " : Where to\r\n")
  84. if move == "dorado":
  85. dorado()
  86. elif move == "albrook":
  87. albrook()
  88. elif move == "multiplaza":
  89. multiplaza()
  90. elif move == "calidonia":
  91. calidonia()
  92. elif move == "cinta costera":
  93. cintacostera()
  94. elif move == "panama viejo":
  95. panamaviejo()
  96. else:
  97. send('PRIVMSG ' + nick + " : For money type atm To move type travel available destinations are: dorado\\albrook\\multiplaza\\calidonia\\cinta costera\\panama viejo\r\n")
  98. def options():
  99. while True:
  100. send('PRIVMSG ' + nick + " : !stats, !atm or !travel> \r\n")
  101. move = find
  102. if move == ":!travel":
  103. if hero.money <= 0:
  104. send('PRIVMSG ' + nick + " : You don't have any money\r\n")
  105. else:
  106. engine()
  107. if move == ":!stats":
  108. send('PRIVMSG ' + nick + " : You have %s money and %s life\n") % (hero.money, hero.hp)
  109. elif move == ":!atm":
  110. hero.money += hero.cash
  111. hero.cash = 0
  112. send('PRIVMSG ' + nick + " : You now have %s money\r\n" % hero.money)
  113. if move == ":!end":
  114. send('PRIVMSG ' + nick + " : Thanks for playing Good BYE\r\n")
  115. elif hero.hp <= 0:
  116. send('PRIVMSG ' + nick + " : GAME OVER YOU HAVE NO MORE LIFE\r\n")
  117. def gamestart():
  118. 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""")
  119. while True:
  120. # This fetches the nicks
  121. nick = data.split('!')[0]
  122. nick = nick.replace(':', ' ')
  123. nick = nick.replace(' ', '')
  124. nick = nick.strip(' \t\n\r')
  125. # PING PONG with the IRC server to avoid getting booted
  126. if find('PING') != -1:
  127. send('PONG ' + data.split()[1] + '\r\n')
  128. print "PONG SENT"
  129. print data
  130. # Establishing bot behaviour
  131. elif find(':!Play') != -1:
  132. if user == nick:
  133. send(' PRIVMSG ' + nick + ' : Game Loading')
  134. print data
  135. gamestart(); options()
  136. elif find(':!quit') != -1:
  137. if user == nick:
  138. send(' PRIVMSG ' + channel + ': Good Bye')
  139. send('quit\r\n')
  140. print data
  141. quit()
  142.