Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.81 KB | None | 0 0
  1. from twisted.words.protocols import irc
  2. from twisted.internet import protocol
  3. from twisted.internet import reactor
  4. import random
  5.  
  6. #mlock the modes, set +v the sexy way ie +vvvvvvvvv
  7. #give owner more privs, such as forceing votes, forcing leaves etc, maybe give half op so can kick faggots
  8. #start >lynch command
  9. #read commands, descriptions etc from a xml file
  10. #fix bugs and tidy code
  11.  
  12. oper_pass = ''
  13. ns_pass = ''
  14.  
  15. min_players = 3
  16. min_players_2_wolves = 6
  17.  
  18.  
  19.  
  20. class WolfBot(irc.IRCClient):
  21.    
  22.     def _get_nickname(self):
  23.         return self.factory.nickname
  24.    
  25.     nickname = property(_get_nickname)
  26.  
  27.     def signedOn(self):
  28.         self.sendLine('OPER %s' % oper_pass)
  29.         self.mode(self.factory.nickname,True,'BH',None,None,None)
  30.         self.msg('Nickserv','id %s' % ns_pass)
  31.         self.msg('Operserv', 'set superadmin on')
  32.         self.join(self.factory.channel)
  33.        
  34.     def player_gone(self,user,channel):
  35.         if self.game_schedule:
  36.             del self.players[user]
  37.             self.msg(channel,'%s just dissapeard, nothing of value was lost' % user)
  38.         elif self.game:
  39.             role_num = self.players.get(user, None)
  40.             role = self.roles.get(role_num,None)
  41.             del self.players[user]
  42.             #module gotta fit in here
  43.             if role_num == 1:
  44.                 self.msg(channel,'%s just dissapeard, %s was a %s, wolf gone' % (user,user,role))
  45.             elif role_num == 2:
  46.                 self.msg(channel,'%s just dissapeard, %s was a %s, seer gone' % (user,user,role))
  47.             else:
  48.                 self.msg(channel,'%s just dissapeard, %s was a %s, nothing of value was lost' % (user,user,role))
  49.             #push vote_update
  50.             #waiting on etc
  51.         if len(self.players) < min_players: #higher if not enough players left to play
  52.             self.game = False
  53.             self.game_schedule = False
  54.             self.msg(channel,'Not enough players remaining, game cancelled...RIP')
  55.         elif user == self.owner:
  56.             self.owner = random.choice(self.players.keys())
  57.             self.msg(channel,'%s was the game owner, %s has become the owner now' % (user,self.owner))
  58.    
  59.     def assign_roles(self,channel):
  60.         if len(self.players) >= min_players_2_wolves:
  61.             self.msg(channel,'There are enough players for 2 wolves')
  62.             tmp = random.sample(self.players.keys(),3)
  63.         else:
  64.             tmp = random.sample(self.players.keys(),2)
  65.         self.seer = random.choice(tmp)
  66.         tmp.remove(self.seer)
  67.         self.wolves = tmp
  68.         for player in self.players.keys():
  69.             if player == self.seer:
  70.                 self.players[player] = 2
  71.             elif player in self.wolves:
  72.                 self.players[player] = 1
  73.                 self.wolf_targets[player] = None
  74.             else:
  75.                 self.players[player] = 3
  76.  
  77.         self.mode(channel,True,'m',None,None,None)
  78.         for player in self.players.keys():
  79.             #get descriptions etc
  80.             self.mode(channel,True,'v',None,player,None)
  81.             self.msg(player,'You are a %s' % self.roles.get(self.players.get(player, None),None))
  82.             #get descriptions
  83.             if player == self.seer:
  84.                 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')
  85.             #gotta be a better way of determining other wolf, other than a ghetto loop, ask e
  86.             elif player in self.wolves:
  87.                 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')
  88.                 if len(self.wolves) == 2:
  89.                     for wolf in self.wolves:
  90.                         if wolf != player:
  91.                             self.msg(player,'There are two wolves in this game, the other wolf is %s, you must agree on the same targets.' % wolf)
  92.             else:
  93.                 self.msg(player,'As a villager, your objective is to determine any and all wolves and make sure they are lynched in the morning')
  94.         #get descriptions etc
  95.         self.msg(channel,'Nightime begins in the village, niggery is afoot')
  96.        
  97.     def check_night_finished(self):
  98.         if self.seen and self.killed:
  99.             #get descriptions
  100.             self.mode(self.factory.channel,False,'v',None,self.wolf_target,None)
  101.             self.msg(self.factory.channel,'The night has ended, villagers awake to find the mutilated dead body of %s' % self.wolf_target)
  102.             self.msg(self.factory.channel,'%s was a %s' % (self.wolf_target,self.roles.get(self.players.get(self.wolf_target, None),None)))
  103.             #sync variables
  104.             lynch_time = True
  105.             self.dead.append(self.wolf_target)
  106.             del self.players[self.wolf_target]
  107.  
  108.    
  109.     game = False
  110.     game_schedule = False
  111.     lynch_time = False
  112.     #has the seer used his one see?
  113.     seen = False
  114.     #has the wolf/wolves killed?
  115.     killed = False
  116.     #used to track targets when more than one wolf
  117.     wolf_targets = {}
  118.     wolf_target = None
  119.     dead = []
  120.     owner = None #game owner/starter/founder
  121.     #1 == wolf, #2 == seer, #3 == villager
  122.     roles = {1:'Wolf',2:'Seer',3:'Villager'}
  123.     players = {}
  124.    
  125.     def userLeft(self, user, channel):
  126.         if user in self.players:
  127.             self.player_gone(user,channel)
  128.            
  129.     def userQuit(self, user, quitMessage):
  130.         if user in self.players:
  131.             self.player_gone(user,self.factory.channel)
  132.        
  133.     def userKicked(self, user, channel, kicker, message):
  134.         if user in self.players:
  135.             self.player_gone(user,channel)
  136.  
  137.     def irc_NICK(self, user, params):
  138.         old_nick = user.split('!')[0]
  139.         new_nick = params[0]
  140.         if old_nick in self.players:
  141.             role = self.players.get(old_nick, None)
  142.             if role == 1:
  143.                 self.wolves[self.wolves.index(old_nick)] = new_nick
  144.                 target = self.wolf_target.get(old_nick,None)
  145.                 del self.wolf_target[old_nick]
  146.                 self.wolf_target[new_nick] = target
  147.             elif role == 2:
  148.                 self.seer = new_nick
  149.             #update votes etc
  150.             del self.players[old_nick]
  151.             self.players[new_nick] = role
  152.             if old_nick == self.owner:
  153.                 self.owner = new_nick
  154.             self.notice(new_nick,'Tracked your nick change')
  155.  
  156.     def privmsg(self, user, channel, msg):
  157.         nick = user.split('!')[0]
  158.         command = msg.split(' ')[0]
  159.  
  160.         if command == '>join' and channel == self.factory.channel:
  161.             if self.game and nick in self.players:
  162.                 self.notice(nick,'You are already in the game in progress')
  163.             elif self.game and nick not in self.players:
  164.                 self.notice(nick,'You may not join a game in progress')
  165.             elif self.game_schedule and nick in self.players:
  166.                 self.notice(nick,'You have already joined')
  167.             elif self.game_schedule and nick not in self.players:
  168.                 self.msg(channel,'%s has just joined the game' % nick)
  169.                 self.players[nick] = None
  170.             else:
  171.                 self.notice(nick,'No game at the moment, use >start to begin one')
  172.                
  173.         elif command == '>leave' and channel == self.factory.channel:
  174.             if self.game and nick in self.players:
  175.                 #force them to stay in a game imo
  176.                 self.notice(nick,'You cant leave a game in progress')
  177.             elif self.game and nick not in self.players:
  178.                 self.notice(nick,'You cant leave a game you\'re not a part of')
  179.             elif self.game_schedule and nick in self.players:
  180.                 del self.players[nick]
  181.                 self.notice(nick,'You have just left the game')
  182.             elif self.game_schedule and nick not in self.players:
  183.                 self.notice(nick,'You cant leave a game you\'re not a part of')
  184.             else:
  185.                 self.notice(nick,'No game at the moment, use >start to begin one')
  186.            
  187.         elif command == '>start' and channel == self.factory.channel:
  188.             #expand
  189.             if self.game or self.game_schedule:
  190.                 self.notice(nick,'Game already in progress')
  191.             else:
  192.                 self.game_schedule = True
  193.                 self.owner = nick
  194.                 self.players[nick] = None
  195.                 self.notice(nick,'You are the game owner, use >begin to begin the game one all players have joined')
  196.                 self.msg(channel,'%s has just started a new game, use >join to join!' % nick)
  197.                
  198.         elif command == '>begin' and channel == self.factory.channel:
  199.             if self.game:
  200.                 self.notice(nick,'Game already in progress')
  201.             elif nick != self.owner and self.game_schedule:
  202.                 self.notice(nick,'Only the game owner can begin the game, current owner: %s' % self.owner)
  203.             elif nick == self.owner and self.game_schedule:
  204.                 if len(self.players) < min_players:
  205.                     self.msg(channel,'Not enough players to begin the new game')
  206.                 else:
  207.                     self.game_schedule = False
  208.                     self.game = True
  209.                     self.msg(channel,'New game starting, assigining roles')
  210.                     self.assign_roles(channel)
  211.             elif not self.game_schedule:
  212.                 self.notice(nick,'No game at the moment, use >start to begin one')
  213.            
  214.     #   elif command == '>lynch' and channel == self.factory.channel:
  215.            
  216.         elif command == '>kill' and channel == self.nickname:
  217.         #2 wolves must agree
  218.             if self.lynch_time and nick in self.wolves:
  219.                 self.msg(nick,'Now is not the time for that')
  220.             if not self.lynch_time and nick in self.wolves:
  221.                 if self.killed:
  222.                     if len(self.wolves) == 2:
  223.                         self.msg(nick,'You and the other wolf have already decided on your target')
  224.                     else:
  225.                         try:
  226.                             target = msg.split(' ')[1]
  227.                         except IndexError, e:
  228.                             self.msg(nick,'No target given')
  229.                         else:
  230.                             if target == nick:
  231.                                 self.msg(nick,'You cannot kill yourself')
  232.                             elif target in self.dead:
  233.                                 self.msg(nick,'%s is already dead' % target)
  234.                             elif target in self.players:
  235.                                 self.msg(nick,'Target updated')
  236.                                 self.wolf_target = target
  237.                                 self.check_night_finished()
  238.                 else:
  239.                     try:
  240.                         target = msg.split(' ')[1]
  241.                     except IndexError, e:
  242.                         self.msg(nick,'No target given')
  243.                     else:
  244.                         if target == nick:
  245.                             self.msg(nick,'You cannot kill yourself')
  246.                         elif target in self.dead:
  247.                             self.msg(nick,'%s is already dead' % target)
  248.                         elif target in self.players and len(self.wolves) != 2:
  249.                             self.msg(nick,'Target set')
  250.                             self.wolf_target = target
  251.                             self.check_night_finished()
  252.                         elif target in self.wolves:
  253.                             self.msg(nick,'You may not kill another wolf')
  254.                         elif target in self.players and len(self.wolves) == 2:
  255.                             self.msg(nick,'Target set')
  256.                             self.wolf_targets[nick] = target
  257.                             #determine shit, gotta be a better way of determining other wolf, other than a ghetto loop, ask e
  258.                             for wolf in self.wolves:
  259.                                 if wolf != nick:
  260.                                     if self.wolf_targets.get(wolf, None) == target:
  261.                                         self.msg('%s,%s' % (nick,wolf),'Target has been agreed on')
  262.                                         self.wolf_target = target
  263.                                         self.killed = True
  264.                                         self.check_night_finished()
  265.                                     elif self.wolf_targets.get(wolf, None) == None:
  266.                                         self.msg(nick,'%s hasn\'t chose a target yet' % wolf)
  267.                                     else:
  268.                                         self.msg('%s,%s' % (nick,wolf),'You have both chosen different targets, you need to agree')                    
  269.                         else:
  270.                             self.msg(nick,'%s isn\'t playing' % target)
  271.                        
  272.                        
  273.         elif command == '>see' and channel == self.nickname:
  274.             #if nick in self.dead:
  275.             #   self.msg(nick,'You are dead and should stfu, kthx')
  276.             if self.lynch_time and nick == self.seer:
  277.                 self.msg(nick,'Now is not the time for that')
  278.             elif not self.lynch_time and nick == self.seer:
  279.                 if self.seen:
  280.                     self.msg(nick,'You have already used your talent for tonight')
  281.                 else:
  282.                     try:
  283.                         target = msg.split(' ')[1]
  284.                     except IndexError, e:
  285.                         self.msg(nick,'No target given')
  286.                     else:
  287.                         if target == nick:
  288.                             self.msg(nick,'You already know what you are...try again')
  289.                         elif target in self.dead:
  290.                             self.msg(nick,'%s is dead' % target)
  291.                         elif target in self.players:
  292.                             self.msg(nick,'You are sure %s is a %s' % (target, self.roles.get(self.players.get(target, None),None)))
  293.                             self.seen = True
  294.                             self.check_night_finished()
  295.                         else:
  296.                             self.msg(nick,'%s isn\'t playing' % target)
  297.        
  298.     def ctcpQuery(self, user, channel, messages):
  299.         print 'Faggot is ctcp\'in'
  300.  
  301.  
  302. class WolfBotFactory(protocol.ClientFactory):
  303.     protocol = WolfBot
  304.  
  305.     def __init__(self, channel, nickname='Premium_Bot'):
  306.         self.channel = channel
  307.         self.nickname = nickname
  308.        
  309.     def clientConnectionLost(self, connector, reason):
  310.         connector.connect()
  311.        
  312.     def clientConnectionFailed(self, connector, reason):
  313.         print "Connection failure:", reason
  314.         reactor.stop()
  315.  
  316. if __name__ == '__main__':
  317.     reactor.connectTCP('zeus.skidsr.us', 6667, WolfBotFactory('#venuism'))
  318.     reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement