-
- from random import randint
- import socket
-
- # This is to identify your user/pass to the IRC server so your bot can be masked
- # Thought it was safer to have it on user input rather than hardcoded
- # user is important cause it gives only the user control of the bot
- user = raw_input("enter user ")
- secret = raw_input("enter password ")
-
- # name of the bot, channel and irc network
- botnick = raw_input("BOT NICKNAME ")
- channel = raw_input("IRC CHANNEL ")
- network = 'irc.freenode.net'
-
- # irc protocol
- port = 6667
- irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- irc.connect((network, port))
- print irc.recv(4096)
-
- # bot will identify to the IRC server and join desired channel
- irc.send('NICK ' + botnick + '\r\n')
- irc.send('USER vitebot vitebot vitebot:Python IRC\r\n')
- irc.send('nickserv identify ' + user + ' ' + secret+ '\r\n')
- irc.send('JOIN '+ channel +'\r\n')
- irc.send('PRIVMSG '+ channel +' :Hello World.\r\n')
-
-
- class Nick:
-
- def __init__(self, nick = 0):
- self.nick = nick
-
- class Hero:
-
- def __init__(self, hp= 100, money = 0, cash = 100):
- self.hp = hp
- self.money = money
- self.cash = cash
-
- def eat(self):
- self.hp = self.hp + 1
-
- def move(self):
- self.move = move
-
- class Bad:
-
- def __init__(self, hp = 100):
- self.hp = hp
-
- class FIGHT:
- def badattack():
- x = randint(0, 20)
- hero.hp -= x
-
- def heroattack():
- y = randint(0, 20)
- print "Hero scores %s " % y
- bad.hp -= y
-
- # Creating shortcut variables
- data = irc.recv(4096)
- find = data.find
- send = irc.send
- attack = FIGHT()
- hero = Hero()
- bad = Bad()
- move = hero.move
- nick = Nick.nick
-
- # game script
- def dorado():
- send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
- send('PRIVMSG ' + nick + " : You have reached dorado\r\n")
- options()
-
- def albrook():
- send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
- send('PRIVMSG ' + nick + " : You have reached albrook\r\n")
- options()
-
- def multiplaza():
- send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
- send('PRIVMSG ' + nick + " : You have reached multiplaza\r\n")
- options()
-
- def calidonia():
- send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
- send('PRIVMSG ' + nick + " : You have reached calidonia\r\n")
- options()
-
- def cintacostera():
- send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
- send('PRIVMSG ' + nick + " : You have reached cinta costera\r\n")
- options()
-
- def panamaviejo():
- send('PRIVMSG ' + nick + " : You now have %s\r\n" % hero.money)
- send('PRIVMSG ' + nick + " : You have reached Panama Viejo\r\n")
- options()
-
- def engine():
- send('PRIVMSG ' + nick + " : Where to\r\n")
- if move == "dorado":
- dorado()
- elif move == "albrook":
- albrook()
- elif move == "multiplaza":
- multiplaza()
- elif move == "calidonia":
- calidonia()
- elif move == "cinta costera":
- cintacostera()
- elif move == "panama viejo":
- panamaviejo()
- else:
- send('PRIVMSG ' + nick + " : For money type atm To move type travel available destinations are: dorado\\albrook\\multiplaza\\calidonia\\cinta costera\\panama viejo\r\n")
-
-
- def options():
-
- while True:
- send('PRIVMSG ' + nick + " : !stats, !atm or !travel> \r\n")
- move = find
- if move == ":!travel":
- if hero.money <= 0:
- send('PRIVMSG ' + nick + " : You don't have any money\r\n")
- else:
- engine()
- if move == ":!stats":
- send('PRIVMSG ' + nick + " : You have %s money and %s life\n") % (hero.money, hero.hp)
-
- elif move == ":!atm":
- hero.money += hero.cash
- hero.cash = 0
- send('PRIVMSG ' + nick + " : You now have %s money\r\n" % hero.money)
-
- if move == ":!end":
- send('PRIVMSG ' + nick + " : Thanks for playing Good BYE\r\n")
-
- elif hero.hp <= 0:
- send('PRIVMSG ' + nick + " : GAME OVER YOU HAVE NO MORE LIFE\r\n")
-
- def gamestart():
- 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"""
-
- while True:
- # This fetches the nicks
- nick = data.split('!')[0]
- nick = nick.replace(':', ' ')
- nick = nick.replace(' ', '')
- nick = nick.strip(' \t\n\r')
-
- # PING PONG with the IRC server to avoid getting booted
- if find('PING') != -1:
- send('PONG ' + data.split()[1] + '\r\n')
- print "PONG SENT"
- print data
-
- # Establishing bot behaviour
- elif find(':!gamestart'):
- print "Starting Game with " + nick
- gamestart(); options()
-
- elif find(':!quit') != -1:
- if user == nick:
- send(' PRIVMSG ' + channel + ': Good Bye')
- send('quit\r\n')
- print data
- quit()
-
- File "ircgame.py", line 148
- while True:
- ^
- SyntaxError: invalid syntax
-