Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from twisted.words.protocols import irc
- from twisted.internet import protocol
- from twisted.internet import reactor
- import random
- #mlock the modes, set +v the sexy way ie +vvvvvvvvv
- #give owner more privs, such as forceing votes, forcing leaves etc, maybe give half op so can kick faggots
- #start >lynch command
- #read commands, descriptions etc from a xml file
- #fix bugs and tidy code
- oper_pass = ''
- ns_pass = ''
- min_players = 3
- min_players_2_wolves = 6
- class WolfBot(irc.IRCClient):
- def _get_nickname(self):
- return self.factory.nickname
- nickname = property(_get_nickname)
- def signedOn(self):
- self.sendLine('OPER %s' % oper_pass)
- self.mode(self.factory.nickname,True,'BH',None,None,None)
- self.msg('Nickserv','id %s' % ns_pass)
- self.msg('Operserv', 'set superadmin on')
- self.join(self.factory.channel)
- def player_gone(self,user,channel):
- if self.game_schedule:
- del self.players[user]
- self.msg(channel,'%s just dissapeard, nothing of value was lost' % user)
- elif self.game:
- role_num = self.players.get(user, None)
- role = self.roles.get(role_num,None)
- del self.players[user]
- #module gotta fit in here
- if role_num == 1:
- self.msg(channel,'%s just dissapeard, %s was a %s, wolf gone' % (user,user,role))
- elif role_num == 2:
- self.msg(channel,'%s just dissapeard, %s was a %s, seer gone' % (user,user,role))
- else:
- self.msg(channel,'%s just dissapeard, %s was a %s, nothing of value was lost' % (user,user,role))
- #push vote_update
- #waiting on etc
- if len(self.players) < min_players: #higher if not enough players left to play
- self.game = False
- self.game_schedule = False
- self.msg(channel,'Not enough players remaining, game cancelled...RIP')
- elif user == self.owner:
- self.owner = random.choice(self.players.keys())
- self.msg(channel,'%s was the game owner, %s has become the owner now' % (user,self.owner))
- def assign_roles(self,channel):
- if len(self.players) >= min_players_2_wolves:
- self.msg(channel,'There are enough players for 2 wolves')
- tmp = random.sample(self.players.keys(),3)
- else:
- tmp = random.sample(self.players.keys(),2)
- self.seer = random.choice(tmp)
- tmp.remove(self.seer)
- self.wolves = tmp
- for player in self.players.keys():
- if player == self.seer:
- self.players[player] = 2
- elif player in self.wolves:
- self.players[player] = 1
- self.wolf_targets[player] = None
- else:
- self.players[player] = 3
- self.mode(channel,True,'m',None,None,None)
- for player in self.players.keys():
- #get descriptions etc
- self.mode(channel,True,'v',None,player,None)
- self.msg(player,'You are a %s' % self.roles.get(self.players.get(player, None),None))
- #get descriptions
- if player == self.seer:
- self.msg(player,'As a seer, once a night you can use >see to determine another players true form. Your objective is to help the villagers lynch all and any wolves that are killing people in the night')
- #gotta be a better way of determining other wolf, other than a ghetto loop, ask e
- elif player in self.wolves:
- self.msg(player,'As a wolf, once a night u can use >kill to kill another player. Your objective is to kill all the villagers and the seer')
- if len(self.wolves) == 2:
- for wolf in self.wolves:
- if wolf != player:
- self.msg(player,'There are two wolves in this game, the other wolf is %s, you must agree on the same targets.' % wolf)
- else:
- self.msg(player,'As a villager, your objective is to determine any and all wolves and make sure they are lynched in the morning')
- #get descriptions etc
- self.msg(channel,'Nightime begins in the village, niggery is afoot')
- def check_night_finished(self):
- if self.seen and self.killed:
- #get descriptions
- self.mode(self.factory.channel,False,'v',None,self.wolf_target,None)
- self.msg(self.factory.channel,'The night has ended, villagers awake to find the mutilated dead body of %s' % self.wolf_target)
- self.msg(self.factory.channel,'%s was a %s' % (self.wolf_target,self.roles.get(self.players.get(self.wolf_target, None),None)))
- #sync variables
- lynch_time = True
- self.dead.append(self.wolf_target)
- del self.players[self.wolf_target]
- game = False
- game_schedule = False
- lynch_time = False
- #has the seer used his one see?
- seen = False
- #has the wolf/wolves killed?
- killed = False
- #used to track targets when more than one wolf
- wolf_targets = {}
- wolf_target = None
- dead = []
- owner = None #game owner/starter/founder
- #1 == wolf, #2 == seer, #3 == villager
- roles = {1:'Wolf',2:'Seer',3:'Villager'}
- players = {}
- def userLeft(self, user, channel):
- if user in self.players:
- self.player_gone(user,channel)
- def userQuit(self, user, quitMessage):
- if user in self.players:
- self.player_gone(user,self.factory.channel)
- def userKicked(self, user, channel, kicker, message):
- if user in self.players:
- self.player_gone(user,channel)
- def irc_NICK(self, user, params):
- old_nick = user.split('!')[0]
- new_nick = params[0]
- if old_nick in self.players:
- role = self.players.get(old_nick, None)
- if role == 1:
- self.wolves[self.wolves.index(old_nick)] = new_nick
- target = self.wolf_target.get(old_nick,None)
- del self.wolf_target[old_nick]
- self.wolf_target[new_nick] = target
- elif role == 2:
- self.seer = new_nick
- #update votes etc
- del self.players[old_nick]
- self.players[new_nick] = role
- if old_nick == self.owner:
- self.owner = new_nick
- self.notice(new_nick,'Tracked your nick change')
- def privmsg(self, user, channel, msg):
- nick = user.split('!')[0]
- command = msg.split(' ')[0]
- if command == '>join' and channel == self.factory.channel:
- if self.game and nick in self.players:
- self.notice(nick,'You are already in the game in progress')
- elif self.game and nick not in self.players:
- self.notice(nick,'You may not join a game in progress')
- elif self.game_schedule and nick in self.players:
- self.notice(nick,'You have already joined')
- elif self.game_schedule and nick not in self.players:
- self.msg(channel,'%s has just joined the game' % nick)
- self.players[nick] = None
- else:
- self.notice(nick,'No game at the moment, use >start to begin one')
- elif command == '>leave' and channel == self.factory.channel:
- if self.game and nick in self.players:
- #force them to stay in a game imo
- self.notice(nick,'You cant leave a game in progress')
- elif self.game and nick not in self.players:
- self.notice(nick,'You cant leave a game you\'re not a part of')
- elif self.game_schedule and nick in self.players:
- del self.players[nick]
- self.notice(nick,'You have just left the game')
- elif self.game_schedule and nick not in self.players:
- self.notice(nick,'You cant leave a game you\'re not a part of')
- else:
- self.notice(nick,'No game at the moment, use >start to begin one')
- elif command == '>start' and channel == self.factory.channel:
- #expand
- if self.game or self.game_schedule:
- self.notice(nick,'Game already in progress')
- else:
- self.game_schedule = True
- self.owner = nick
- self.players[nick] = None
- self.notice(nick,'You are the game owner, use >begin to begin the game one all players have joined')
- self.msg(channel,'%s has just started a new game, use >join to join!' % nick)
- elif command == '>begin' and channel == self.factory.channel:
- if self.game:
- self.notice(nick,'Game already in progress')
- elif nick != self.owner and self.game_schedule:
- self.notice(nick,'Only the game owner can begin the game, current owner: %s' % self.owner)
- elif nick == self.owner and self.game_schedule:
- if len(self.players) < min_players:
- self.msg(channel,'Not enough players to begin the new game')
- else:
- self.game_schedule = False
- self.game = True
- self.msg(channel,'New game starting, assigining roles')
- self.assign_roles(channel)
- elif not self.game_schedule:
- self.notice(nick,'No game at the moment, use >start to begin one')
- # elif command == '>lynch' and channel == self.factory.channel:
- elif command == '>kill' and channel == self.nickname:
- #2 wolves must agree
- if self.lynch_time and nick in self.wolves:
- self.msg(nick,'Now is not the time for that')
- if not self.lynch_time and nick in self.wolves:
- if self.killed:
- if len(self.wolves) == 2:
- self.msg(nick,'You and the other wolf have already decided on your target')
- else:
- try:
- target = msg.split(' ')[1]
- except IndexError, e:
- self.msg(nick,'No target given')
- else:
- if target == nick:
- self.msg(nick,'You cannot kill yourself')
- elif target in self.dead:
- self.msg(nick,'%s is already dead' % target)
- elif target in self.players:
- self.msg(nick,'Target updated')
- self.wolf_target = target
- self.check_night_finished()
- else:
- try:
- target = msg.split(' ')[1]
- except IndexError, e:
- self.msg(nick,'No target given')
- else:
- if target == nick:
- self.msg(nick,'You cannot kill yourself')
- elif target in self.dead:
- self.msg(nick,'%s is already dead' % target)
- elif target in self.players and len(self.wolves) != 2:
- self.msg(nick,'Target set')
- self.wolf_target = target
- self.check_night_finished()
- elif target in self.wolves:
- self.msg(nick,'You may not kill another wolf')
- elif target in self.players and len(self.wolves) == 2:
- self.msg(nick,'Target set')
- self.wolf_targets[nick] = target
- #determine shit, gotta be a better way of determining other wolf, other than a ghetto loop, ask e
- for wolf in self.wolves:
- if wolf != nick:
- if self.wolf_targets.get(wolf, None) == target:
- self.msg('%s,%s' % (nick,wolf),'Target has been agreed on')
- self.wolf_target = target
- self.killed = True
- self.check_night_finished()
- elif self.wolf_targets.get(wolf, None) == None:
- self.msg(nick,'%s hasn\'t chose a target yet' % wolf)
- else:
- self.msg('%s,%s' % (nick,wolf),'You have both chosen different targets, you need to agree')
- else:
- self.msg(nick,'%s isn\'t playing' % target)
- elif command == '>see' and channel == self.nickname:
- #if nick in self.dead:
- # self.msg(nick,'You are dead and should stfu, kthx')
- if self.lynch_time and nick == self.seer:
- self.msg(nick,'Now is not the time for that')
- elif not self.lynch_time and nick == self.seer:
- if self.seen:
- self.msg(nick,'You have already used your talent for tonight')
- else:
- try:
- target = msg.split(' ')[1]
- except IndexError, e:
- self.msg(nick,'No target given')
- else:
- if target == nick:
- self.msg(nick,'You already know what you are...try again')
- elif target in self.dead:
- self.msg(nick,'%s is dead' % target)
- elif target in self.players:
- self.msg(nick,'You are sure %s is a %s' % (target, self.roles.get(self.players.get(target, None),None)))
- self.seen = True
- self.check_night_finished()
- else:
- self.msg(nick,'%s isn\'t playing' % target)
- def ctcpQuery(self, user, channel, messages):
- print 'Faggot is ctcp\'in'
- class WolfBotFactory(protocol.ClientFactory):
- protocol = WolfBot
- def __init__(self, channel, nickname='Premium_Bot'):
- self.channel = channel
- self.nickname = nickname
- def clientConnectionLost(self, connector, reason):
- connector.connect()
- def clientConnectionFailed(self, connector, reason):
- print "Connection failure:", reason
- reactor.stop()
- if __name__ == '__main__':
- reactor.connectTCP('zeus.skidsr.us', 6667, WolfBotFactory('#venuism'))
- reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement