Advertisement
Guest User

Untitled

a guest
May 6th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 36.65 KB | None | 0 0
  1. #!/usr/bin/python
  2. # this bot better beat You and Younata! :P
  3. # todo: fix counterclaims after a person is already chosen as a PR | better telling if a person is claiming | specify nokill in the mchat
  4. import random, re, time, threading
  5. from itertools import *
  6. from twisted.words.protocols import irc
  7. from twisted.internet import reactor, protocol, task, defer
  8. global debug
  9. debug = True
  10.  
  11. class Komurin(irc.IRCClient):
  12.    
  13.     def __init__(self):
  14.         self.nickname = "Trinity"
  15.         self.password = ""
  16.         self.version = "1.0.0"
  17.         self.trigger = "-"
  18.         self.ubertrigger = "-"
  19.         if debug == False:
  20.             self.mafialeader = 'Siobhan'
  21.             self.mafiaroom = '#mafia'
  22.             self.autojoin = False
  23.         else:
  24.             self.mafialeader = 'MafiaTester'
  25.             self.mafiaroom = '#mafia-testing'
  26.             self.autojoin = True
  27.            
  28.         #game specific starting option
  29.         self.ingame = False
  30.         self.daynum = 0
  31.         self.nightnum = 0
  32.         self.gametime = None
  33.         self.alivelist = []
  34.         self.deadlist = []
  35.         self.sheeprole = None
  36.         self.mafiafriendlist = []
  37.         self.havemchatted = False
  38.         self.rolelist = {}
  39.         self.newdie = "None"
  40.         self.doneaction = False
  41.         self.claimdict = {}
  42.         self.claimdict['doc'] = []
  43.         self.claimdict['cop'] = []
  44.         self.claimdict['det'] = []
  45.         self.claimdict['oc'] = []
  46.         self.saveddict = {}
  47.         self.scumlevel = {}
  48.         self.topscum = None
  49.         self.doc = None
  50.         self.det = None
  51.         self.cop = None
  52.         self.gamesetdid = False
  53.         self.claimeddoc = False
  54.         self.claimeddet = False
  55.         self.claimedcop = False
  56.            
  57.         #responses
  58.         self.coppos = ["I'm cop and have guilty!", "Finally got a guilty report. Ya I am cop, btw", "Mesa the copsa!", "G.U.I.L.T.Y. report right here", "Ya I'm the cop", "You didn't think I could do it, but I am cop and I got a guilty report right here:", "w00t, I rock at cop! guilty report:"]
  59.         self.copposrep = " checked %s night %d"
  60.         self.copinno = ["I'm cop and have got inno!", "Yo, I'm da fuzz, got report.", "Ya I didn't want to reveal till now, I am cop, but I only got some false reports.", "<== Cop"]
  61.         self.copinnorep = " checked %s night %d"
  62.         self.docsave = ["I'm doc!", "Might be a mistake, but, ya, I'm doc.", "Doc here!", "Bitch, I'm the DOC,"]
  63.         self.docsaverep = " saved %s night %d"
  64.         self.detness = ["Ya, I'm detective.","Guess it's time to reveal myself, I'm detective.", "<--Detective "]
  65.         self.detrep = " %s was a %s"
  66.         self.ocrep = ["Ya, don't think I really need to say it, but, ya, I'm OC", "OC over here", "< OC","I'm oc all the way, baby!"]
  67.         self.myloarg = ["It's mylo, right? Current strategy dictates a nolynch here", "MYLO == nolynch time", "Ya, my programming points me to the nl route", "Definitely not a random lynch partay time", "ehh I don't wanna, but... it's mylo, I think i have to nolynch", "You say MYLO, I say NOLYNCH"]
  68.         self.randarg = ["We can afford a rl, right? ya, I'm going to do that.", "Nolynching == Nofun", "Ya I hate nolynching", "We have the chance to rl, let's take it!"]
  69.         self.nlarg = ["I dont want to take the risk of an rl right now :/", "RL is the path to the fail side"]
  70.         self.lyloreason = ["If my sources are correct, it is Lylo right now!", "It is Lylo", "Lylo ahoy!", "L.Y.L.O.... L.Y.L.O. and LYLO was his nameo!", "No, it ain't mylo, it lylo, biatch!"]
  71.         self.notmafia = ["Whoa, not scum here.", "If I haven't claimed yet, there's a reason, I wouldn't wanna be killed. If I have claimed, then it's all your fault if we lose.", "If you guys want to risk killing me and losing the game, go ahead.", "You're really willing to take this risk?", "WHAO WHOA", "you're gonna make all of us lose", "Seriously?", "I'm not scum", "You are wrong. Dead wrong"]
  72.         self.explainlynchscum = ["I have intensly studied the data and I have reached my conclusion as to who seems to be the scummiest.", "I know who must be scum!", "I have a hunch...", "I think I know who it is", "After reviewing the evidence, my hunch is secure", "*yawn* oh what? it's time to lynch?", "ya I know what I'm talking about, %s", "the mafia is..."]
  73.         self.alreadylynched = ["I have said my word.", "I have nothing else to say.", "I already lynched! look above!", "lrn2read, i've already lynched and i'm sticking with it!", "WHY WON'T YOU LISTEN TO ME??? I ALREADY LYNCHED!!", "I'm done lynching for today, good night.. zzzzzz"]
  74.         self.scumalias = "(scum|mafia|maf|scummy|scumbuddies|guilty)"
  75.         self.notinmsg = "(nt|n't|no|any|\?|who|what|how|where|other|she|he|someone|else|it|keep|either|or|is|over here)"
  76.         self.docalias = "(doc|doctor|medic|med|phd)"
  77.         self.copalias = "(cop|sheriff|police|popo|fuzz)"
  78.         self.detalias = "(det|detective|mort|mortician|deticitive)"
  79.         self.claiming = "(<|i'm|im|i am)"
  80.         self.scummystuff = "(i am not scum|not scum|i am|he is|she is|not mafia|not maf|not it|let's lynch|i'm|liar|massclaim|claim)"
  81.         self.decidethis = "(decide|think|what|do you|who|sure)"
  82.         self.copfoundscum = "(is scum|is mafia|lynch)"
  83.        
  84.        
  85.            
  86.     def connectionMade(self):
  87.         irc.IRCClient.connectionMade(self)
  88.        
  89.     def connectionLost(self, reason):
  90.         print("LOST CONNECTION! REASON:  %s" % reason)
  91.         irc.IRCClient.connectionLost(self, reason)
  92.         reactor.start()
  93.  
  94.     def signedOn(self):
  95.         self.join(self.factory.channel)
  96.         self.mode(self.nickname, True, '+B', limit=None, user=self.nickname)
  97.         print('Joined irc.foonetic.net as %s' %(self.nickname))
  98.        
  99.     def joined(self, channel):
  100.         print('Joined %s' %(channel))
  101.         self.me(channel, 'version '+self.version)
  102.        
  103.     def noticed(self, user, channel, msg):
  104.         user = user.split('!', 1)[0]
  105.         if user == self.mafialeader:
  106.             print '<%s> %s' % (user, msg)
  107.             self.msgparser(user, channel, msg)
  108.            
  109.     def privmsg(self, user, channel, msg):
  110.         user = user.split('!', 1)[0]
  111.         msg = msg.rstrip()
  112.         if self.ingame:
  113.             self.msgparser(user, channel, msg)
  114.         elif msg.startswith("A new game has begun!") and user == self.mafialeader:
  115.             print 'game has begun!'
  116.             self.ingame = True
  117.             self.daynum = 0
  118.             self.nightnum = 0
  119.             self.gametime = None
  120.             #put ingame variables here
  121.             self.isdoc = False
  122.             self.iscop = False
  123.             self.isdet = False
  124.             self.doc = None
  125.             self.det = None
  126.             self.cop = None
  127.             self.maflist = {}
  128.             self.innolist = {}
  129.             self.alivelist = []
  130.             self.deadlist = []
  131.             self.sheeprole = None
  132.             self.mafiafriendlist = []
  133.             self.havemchatted = False
  134.             self.rolelist = {}
  135.             self.newdie = 'None'
  136.             self.doneaction = False
  137.             self.claimdict = {}
  138.             self.claimdict['doc'] = []
  139.             self.claimdict['cop'] = []
  140.             self.claimdict['det'] = []
  141.             self.claimdict['oc'] = []
  142.             self.saveddict = {}
  143.             self.scumlevel = {}
  144.             self.topscum = None
  145.             self.gamesetdid = False
  146.             self.claimeddoc = False
  147.             self.claimeddet = False
  148.             self.claimedcop = False
  149.         else:
  150.             if msg == self.trigger + 'autojoin.off':
  151.                 self.autojoin = False
  152.                 self.msg(channel, 'Autojoin is OFF')
  153.             elif msg == self.trigger + 'autojoin.on':
  154.                 self.autojoin = True
  155.                 self.msg(channel, 'Autojoin is ON')
  156.             elif msg == self.trigger + 'autojoin':
  157.                 self.msg(channel, 'Autojoin is %s' % self.autojoin)
  158.             elif msg.startswith(self.trigger+'join') and channel == self.mafiaroom:
  159.                 self.msg(channel, '!join')
  160.             elif msg.startswith(self.trigger+'quit') and channel == self.mafiaroom:
  161.                 self.msg(channel, '!quit')
  162.             elif msg.startswith('A new game has been started by') and self.autojoin:
  163.                 self.msg(channel, '!join')
  164.        
  165.     def msgparser(self, user, channel, msg):
  166.         #print "reached msgparser at this: "+msg
  167.         if msg == ("The game has ended.") and self.ingame:
  168.             self.ingame = False
  169.             print "Game has ended"
  170.         elif msg.startswith('Mafia - <'):
  171.             print "recieved a mchat message"
  172.             self.mchat(msg)
  173.         elif self.gametime == 'Day':
  174.             self.daymsgparser(user, channel, msg)
  175.         elif self.gametime == 'Night' or self.gametime == None:
  176.             self.nightmsgparser(user, channel, msg)
  177.  
  178.     def nightmsgparser(self, user, channel, msg):
  179.         #print "reached nightmsgparser at this: "+msg
  180.         if user == self.mafialeader:
  181.             self.mafianightparser(channel, msg)
  182.    
  183.     def mafianightparser(self, channel, msg):
  184.         #print 'reached mafianightparser at '+msg
  185.         if msg.startswith("You're a"):
  186.             print 'identified a role giving'
  187.             self.roleparser(msg)
  188.         elif msg.startswith("Darkness falls:"):
  189.             self.gametime = 'Night'
  190.             self.nightnum += 1
  191.             print self.gametime, self.nightnum
  192.             self.nightaction(channel, msg)
  193.             self.alreadyclaimed = False
  194.             self.doneaction = False
  195.         elif "Sunlight pierces the sky" in msg:
  196.             self.alreadyclaimed = False
  197.             self.alreadylynch = False
  198.             self.doneaction = False
  199.             self.gametime = 'Day'
  200.             self.daynum += 1
  201.             print self.gametime, self.daynum
  202.             if "Noone was killed." in msg:
  203.                 self.msg(channel, "doc++")
  204.                 self.newdie = 'None'
  205.             elif "mutilated body of" in msg:
  206.                 self.msg(channel, "doc--")
  207.                 dead = msg.split(' ')[-1]
  208.                 dead = dead.strip('\x034').strip('\x0f!!')
  209.                 print dead+' is dead :/'
  210.                 self.newdie = dead
  211.                 if self.newdie in self.mafiafriendlist:
  212.                     self.mafiacount -= 1
  213.         elif msg.startswith("The following players are"):
  214.             self.makelivelist(msg)
  215.         elif msg == "There is only one Mafia.":
  216.             self.mafiacount = 1
  217.             print '1 mafia'
  218.         elif msg.startswith('There are') and msg.split(' ')[3] == 'Mafia.':
  219.             self.mafiacount = int(msg.split(' ')[2])
  220.             print str(self.mafiacount)+' mafia'
  221.         elif msg.startswith('The Mafia are'):
  222.             print msg
  223.             self.mafiafriendlist = []
  224.             parsedmaf = msg.split('are ',1)[1].split('.',1)[0].strip().split(', ')
  225.             self.mafiafriendlist.append(parsedmaf)
  226.             self.scumnight(msg)
  227.  
  228.     def nightaction(self, channel, msg):
  229.         print "Alright, going to do an action of some sort. nightaction reached"
  230.         if self.role == 'COP' or self.sheeprole == 'cop':
  231.             print "going to do something as a cop"
  232.             if self.role == 'COP':
  233.                 #choice = None
  234.                 print 'self.maflist:'
  235.                 print self.maflist
  236.                 print 'self.innolist:'
  237.                 print self.innolist
  238.                 alreadycheckedlist = self.maflist.values()+self.innolist.values()
  239.                 checklist = filter(lambda n: n not in alreadycheckedlist, self.alivelist)
  240.                 #while choice == self.nickname or choice == None or choice in self.maflist or choice in self.innolist:
  241.                 #   choice = random.choice(self.alivelist)
  242.                 print checklist
  243.                 try:
  244.                     choice = random.choice(checklist)
  245.                 except IndexError:
  246.                     print 'INDEX ERROR ' * 5
  247.                     choice = random.choice(checklist)
  248.                 self.msg(self.mafialeader, "check "+choice)
  249.                 self.checked = choice
  250.                 print 'checked '+choice
  251.             elif self.role == 'SCUM' and self.sheeprole == 'cop':
  252.                 sheepchoice = None
  253.                 alreadycheckedlist = self.maflist+self.innolist
  254.                 checklist = filter(lambda n: n not in self.alivelist, alreadycheckedlist)
  255.                 checklist.remove(self.nickname)
  256.                 while sheepchoice in self.maflist or sheepchoice in self.innolist or sheepchoice == self.nickname or sheepchoice == None:
  257.                     sheepchoice = random.choice(checklist)
  258.                 sheepchoice = random.choice(checklist)
  259.                 if random.randint(1,3) == 1 and self.mafcount > len(self.maflist):
  260.                     self.maflist[self.nightnum] = sheepchoice
  261.                 else:
  262.                     self.innolist[self.nightnum] = sheepchoice
  263.                 if sheepchoice in self.scumlevel.keys():
  264.                     del self.scumlevel[sheepchoice]
  265.                 self.checked = sheepchoice
  266.                 print 'scumchecked '+ sheepchoice
  267.                 self.scumnight(msg)
  268.         elif self.role == 'DOC' or self.sheeprole == 'doc':
  269.             print 'gonna do something as doc'
  270.             if self.role == 'DOC':
  271.                 choice = None
  272.                 while choice == self.nickname or choice == None:
  273.                     choice = random.choice(self.alivelist)
  274.                 self.msg(self.mafialeader, "save "+choice)
  275.                 self.saved = choice
  276.                 self.saveddict[self.nightnum] = choice
  277.                 print 'saved '+choice
  278.             elif self.role == 'SCUM' and self.sheeprole == 'doc':
  279.                 sheepchoice = None
  280.                 while sheepchoice == self.nickname or sheepchoice == None:
  281.                     sheepchoice = random.choice(self.alivelist)
  282.                 self.saved = sheepchoice
  283.                 self.saveddict[self.nightnum] = sheepchoice
  284.                 print 'scumsaved '+sheepchoice
  285.                 self.scumnight(msg)
  286.         elif self.role == 'SCUM':
  287.             self.scumnight(msg)
  288.         else:
  289.             return
  290.            
  291.     def makelivelist(self, msg):
  292.         if msg.startswith("The following players are still alive:"):
  293.             self.alivelist = []
  294.             self.alivelist = msg.split(':',1)[1].strip().split(', ')
  295.             print 'i got an alivelist '
  296.             print self.alivelist
  297.             for user in self.alivelist:
  298.                 if user not in self.scumlevel.keys():
  299.                     self.scumlevel[user] = 0
  300.             print self.scumlevel
  301.             if self.gamesetdid == False:
  302.                 self.gamesetup()
  303.                 self.gamesetdid = True
  304.             if self.role == 'SCUM':
  305.                 self.sheeproller()
  306.         elif msg.startswith("The following players are dead :"):
  307.             self.deadlist = []
  308.             self.deadlist = msg.split(':',1)[1].strip().split(', ')
  309.             print 'i got a deadlist '
  310.             print self.deadlist
  311.             for user in self.deadlist:
  312.                 if user in self.scumlevel.keys():
  313.                     del self.scumlevel[user]
  314.             print self.scumlevel
  315.         self.lylomylo()
  316.    
  317.     def lylomylo(self):
  318.         x = 0
  319.         mafnum = self.mafiacount
  320.         for role in self.rolelist.values():
  321.             if role.lower == 'mafia':
  322.                 mafnum -= 1
  323.         number = len(self.alivelist) - mafnum
  324.         if number == mafnum + 1:
  325.             self.islylomylo = 'LYLO'
  326.         elif number == mafnum + 2:
  327.             self.islylomylo = 'MYLO'
  328.         else:
  329.             self.islylomylo = 'NONE'
  330.         print 'IT IS '+self.islylomylo
  331.        
  332.     def lyloaction(self, channel):
  333.         print 'reached lyloaction'
  334.         ran = random.randint(5,13)
  335.         time.sleep(ran)
  336.         randomlylochoice = random.choice(self.lyloreason)
  337.         self.msg(channel, randomlylochoice)
  338.         if self.role == 'COP' or self.sheeprole == 'cop':
  339.             print 'going to sheriffday'
  340.             self.sheriffday(channel)
  341.             if len(self.maflist) > 0 and self.doneaction == False:
  342.                 choice = random.choice(self.maflist)
  343.                 self.msg(channel, '!lynch '+choice)
  344.                 self.doneaction = True
  345.             else:
  346.                 if self.doneaction == False:
  347.                     choice = filter(lambda n: n not in self.alivelist, self.innolist)
  348.                     self.msg(channel, '!lynch '+choice)
  349.                     self.doneaction = True
  350.         elif self.role == 'DOC' or self.sheeprole == 'doc':
  351.             print 'going to docday'
  352.             self.docday(channel)
  353.         elif self.role == 'DET' or self.sheeprole == 'det':
  354.             print 'going to detectiveday'
  355.             self.detectiveday(channel)
  356.         else:
  357.             print 'doing my oc thing'
  358.             occhoice = random.choice(self.ocrep)
  359.             self.msg(channel, occhoice)
  360.         self.alreadyclaimed = True
  361.        
  362.     def myloaction(self, channel):
  363.         print 'reached myloaction'
  364.         ran = random.randint(5,13)
  365.         time.sleep(ran)
  366.         if self.role == 'OC' or self.sheeprole == 'oc' or self.role == 'DOC' or self.sheeprole == 'doc':
  367.             print "doing my oc thing"
  368.             occhoice = random.choice(self.ocrep)
  369.             self.msg(channel, occhoice)
  370.         if len(self.maflist) > 0:
  371.             if self.alreadyclaimed == False:
  372.                 self.sheriffday(channel)
  373.                 if len(self.maflist) > 0 and self.doneaction == False:
  374.                     choice = random.choice(self.maflist)
  375.                     self.msg(channel, '!lynch '+choice)
  376.                     self.doneaction = True
  377.                 else:
  378.                     if self.doneaction == False:
  379.                         choice = filter(lambda n: n not in self.alivelist, self.innolist)
  380.                         self.msg(channel, '!lynch '+choice)
  381.                         self.doneaction = True
  382.                 self.alreadyclaimed = True
  383.                 return
  384.         randommylochoice = random.choice(self.myloarg)
  385.         self.msg(channel, randommylochoice)
  386.         self.msg(channel, '!nolynch')
  387.        
  388.            
  389.            
  390.     def roleparser(self, msg):
  391.         #print 'reached mafiaroleparser'
  392.         if 'sheriff' in msg.lower():
  393.             self.role = 'COP'
  394.             print 'I am cop'
  395.         elif 'doctor' in msg.lower():
  396.             self.role = 'DOC'
  397.             self.savedlist = []
  398.             print 'I am doc'
  399.         elif 'detective' in msg.lower():
  400.             self.role = 'DET'
  401.             print 'I am det'
  402.         elif 'mafia' in msg.lower():
  403.             self.role = "SCUM"
  404.             print 'I am scum'
  405.         elif 'citizen' in msg.lower() and not 'mafia' in msg.lower():
  406.             self.role = 'OC'
  407.             print 'I am OC'
  408.         else:
  409.             print "something went wacky in the roleparsing, I can't find any role i'm in"
  410.  
  411.     def daymsgparser(self, user, channel, msg):
  412.         #print "reached daymsgparser"
  413.         if user == self.mafialeader:
  414.             self.mafiadayparser(channel, msg)
  415.         else:
  416.             self.mafiauserparser(user, channel, msg)
  417.    
  418.     def mafiauserparser(self, user, channel, msg):
  419.         print 'reached mafiauserparser'
  420.         if user == self.cop and re.search(self.copfoundscum, msg.lower()):
  421.             for user in self.alivelist:
  422.                 if user.lower() in msg.lower() and user != self.cop:
  423.                     self.scumlevel[user] += 600
  424.         if user in self.alivelist:
  425.             self.scumlevel[user] += 1
  426.             if re.search(self.scummystuff, msg.lower()):
  427.                 print 'someone is acting scummier than usual!'
  428.                 self.someonescummy(user)
  429.         if user == self.cop and 'is' in msg and 'scum' in msg:
  430.             print 'sheriff claimed going to sheriffclaimed()'
  431.             self.sheriffclaimed()
  432.         if 'massclaim' in msg.lower() and re.search(self.notinmsg, msg.lower()):
  433.             print 'someone is calling for a massclaim'
  434.             self.massclaim(channel)
  435.         if re.search(self.decidethis, msg.lower()) and self.username.lower() in msg.lower():
  436.                 print "I'm being asked to decide the fate of someone!"
  437.                 self.lynchscummiest(user, channel)
  438.         if self.nickname in msg:
  439.             if self.islylomylo == 'LYLO':          
  440.                 if msg.lower().strip() == '!lynch trinity':
  441.                     self.lynchingmelylo
  442.                 elif msg.lower().strip() == '!nolynch':
  443.                     self.msg(channel, "WHOA scum alert! You don't nolynch on lylo! %s's definitely a mafia." % user)
  444.                     self.scumlevel[user] += 190
  445.                     print self.scumlevel
  446.             elif msg.lower().strip() == '!lynch trinity':
  447.                 choice = random.choice(self.notmafia)
  448.                 self.msg(channel, choice)
  449.                 self.scumlevel[user] += 100
  450.                 print self.scumlevel
  451.             else:
  452.                 if not re.search(self.notinmsg, msg.lower()) and re.search(self.scumalias, msg.lower()):
  453.                     print "someone be calling me scum!"
  454.                     randomchoice = random.choice(self.notmafia)
  455.                     self.msg(channel, randomchoice)
  456.                     self.scumlevel[user] += 40
  457.                     print self.scumlevel
  458.         if not re.search(self.notinmsg, msg.lower()) and re.search(self.claiming, msg.lower()):
  459.             print 'testing for claim'
  460.             if user not in self.claimdict['doc'] and user not in self.claimdict['cop'] and user not in self.claimdict['det'] and user not in self.maflist:
  461.                 self.checkrole(user, channel, msg)
  462.             elif not re.search(self.notinmsg, msg.lower()) and re.search(self.docalias, msg.lower()) and re.search(self.claiming, msg.lower()):
  463.                 if user in self.claimdict['cop'] or user in self.claimdict['det'] or self.isdoc == False:
  464.                     print 'print someone is trying to claim that they are doc when they arent'
  465.                     self.msg(channel, 'Whoa, %s, you already claimed as something else!' % user)
  466.                     self.scumlevel[user] += 45
  467.             elif not re.search(self.notinmsg, msg.lower()) and re.search(self.copalias, msg.lower()) and re.search(self.claiming, msg.lower()):
  468.                 if user in self.claimdict['doc'] or user in self.claimdict['det'] or self.iscop == False:
  469.                     print 'print someone is trying to claim that they are cop when they arent'
  470.                     self.msg(channel, 'Whoa, %s, you already claimed as something else!' % user)
  471.                     self.scumlevel[user] += 45
  472.             elif not re.search(self.notinmsg, msg.lower()) and re.search(self.detalias, msg.lower()) and re.search(self.claiming, msg.lower()):
  473.                 if user in self.claimdict['doc'] or user in self.claimdict['cop'] or self.isdet == False:
  474.                     print 'print someone is trying to claim that they are det when they arent'
  475.                     self.msg(channel, 'Whoa, %s, you already claimed as something else!' % user)
  476.                     self.scumlevel[user] += 45
  477.    
  478.     def checkrole(self, user, channel, msg):
  479.         print "so far so good user has not previously claimed"
  480.         if re.search(self.docalias, msg.lower()) and self.isdoc == True:
  481.             print 'person is trying to claim doc'
  482.             if self.role == 'DOC' or self.sheeprole == 'doc':
  483.                 print "someone is trying to claim my doc role!"
  484.                 print 'going to docday'
  485.                 self.docday(channel)
  486.                 self.maflist.append(user)
  487.                 self.msg(channel, '!lynch '+user)
  488.                 self.doneaction = True
  489.                 print self.maflist
  490.                 role = 'doc'
  491.             else:
  492.                 print "registering user as doctor claim"
  493.                 self.claimdict['doc'].append(user)
  494.                 print self.claimdict
  495.                 print "starting timer for doc"
  496.                 self.claimeddoc = True
  497.                 doctoclaim = threading.Timer(30, self.claimfinalize)
  498.                 self.msg(channel, 'Alright %s claimed doc, anyone gonna cc?' % user)
  499.                 doctoclaim.start()
  500.         elif re.search(self.copalias, msg.lower()) and self.isdoc == True:
  501.             print 'person is trying to claim cop'
  502.             if self.role == 'COP' or self.sheeprole == 'cop':
  503.                 print 'someone is trying to claim my cop role!'
  504.                 print 'going to sheriffday'
  505.                 self.sheriffday(channel)
  506.                 self.maflist['day'+str(self.daynum)] = user
  507.                 self.msg(channel, '!lynch '+user)
  508.                 self.doneaction = True
  509.                 print self.maflist
  510.             else:
  511.                 print "registering user as sheriff claim"
  512.                 self.claimdict['cop'].append(user)
  513.                 print self.claimdict
  514.                 print 'gonna try the timeout'
  515.                 self.claimedcop = True
  516.                 coptoclaim = threading.Timer(30, self.claimfinalize)
  517.                 self.msg(channel, 'Alright %s claimed cop, anyone gonna cc?' % user)
  518.                 coptoclaim.start()
  519.         elif re.search(self.detalias, msg.lower()) and self.isdet == True:
  520.             print 'person is trying to claim det'
  521.             if self.role == 'DET' or self.sheeprole == 'det':
  522.                 print 'someone is trying to claim my det role!'
  523.                 print 'going to detectiveday'
  524.                 self.detectiveday(channel)
  525.                 self.maflist.append(user)
  526.                 sefl.msg(channel, '!lynch '+user)
  527.                 self.doneaction = True
  528.                 print self.maflist
  529.             else:
  530.                 print 'registering user as det claim'
  531.                 self.claimdict['det'].append(user)
  532.                 print self.claimdict
  533.                 print 'gonna try the timeout'
  534.                 self.claimeddet = True
  535.                 dettoclaim = threading.Timer(30, self.claimfinalize)
  536.                 self.msg(channel, 'Alright %s claimed det, anyone gonna cc?' % user)
  537.                 dettoclaim.start()
  538.                
  539.     def claimfinalize(self, args=[], kwargs={}):
  540.         print 'inclaimfinalize'
  541.         if self.claimeddoc:
  542.             if len(self.claimdict['doc']) == 1:
  543.                 self.doc = self.claimdict['doc'][0]
  544.                 print self.doc+" has been registered as the DOC I am going to remove this user from the scumlevel dict"
  545.                 self.scumlevel[self.doc] -= 100000000000000
  546.                 self.claimeddoc = False
  547.                 self.msg(channel, self.doc+' is cleared in my book')
  548.         elif self.claimedcop:
  549.             if len(self.claimdict['cop']) == 1:
  550.                 self.cop = self.claimdict['cop'][0]
  551.                 print self.cop+" has been registered as the COP I am going to remove this user from the scumlevel dict"
  552.                 self.scumlevel[self.cop] -= 100000000000000
  553.                 self.claimedcop = False
  554.                 self.msg(channel, self.cop+' is cleared in my book')
  555.         elif self.claimeddet:
  556.             if len(self.claimdict['det']) == 1:
  557.                 self.det = self.claimdict['det'][0]
  558.                 print self.det+" has been registered as the DET I am going to remove this user from the scumlevel dict"
  559.                 self.scumlevel[self.det] -= 100000000000000
  560.                 self.claimeddet = False
  561.                 self.msg(channel, self.cop+' is cleared in my book')
  562.  
  563.     def lynchingmelylo(self, channel):
  564.         self.scumlevel[user]+=20
  565.         print self.scumlevel
  566.         print 'someone tried lyching me during lylo, HOW DARE THEY - 1'
  567.         print 'going to tell them my role before i lynch them back - 2'
  568.         if self.doneaction == False:
  569.             if self.role == 'COP' or self.sheeprole == 'cop':
  570.                 print 'going to sheriffday'
  571.                 self.sheriffday(channel)
  572.                 if len(self.maflist) > 0 and self.doneaction == False:
  573.                     choice = random.choice(self.maflist)
  574.                     self.msg(channel, '!lynch '+choice)
  575.                     self.doneaction = True
  576.                 else:
  577.                     if self.doneaction == False:
  578.                         choice = filter(lambda n: n not in self.alivelist, self.innolist)
  579.                         self.msg(channel, '!lynch '+choice)
  580.                         self.doneaction = True
  581.             elif self.role == 'DOC' or self.sheeprole == 'doc':
  582.                 print 'going to docday'
  583.                 self.docday(channel)
  584.                 self.msg(channel, '!lynch '+choice)
  585.                 self.doneaction = True
  586.             elif self.role == 'DET' or self.sheeprole == 'det':
  587.                 print 'going to detectiveday'
  588.                 self.detectiveday(channel)
  589.                 self.msg(channel, '!lynch '+choice)
  590.                 self.doneaction = True
  591.             else:
  592.                 print 'doing my oc thing'
  593.                 occhoice = random.choice(self.ocrep)
  594.                 self.msg(channel, occhoice)
  595.                 self.msg(channel, '!lynch '+choice)
  596.                 self.doneaction = True
  597.             self.alreadyclaimed = True
  598.                
  599.     def sheriffclaimed(self):
  600.         turkey = msg.split(' ')
  601.         print 'the confirmed cop is saying that someone is mafia!'
  602.         for user in self.alivelist:
  603.             if user in turkey:
  604.                 print user+' is apparently mafia!'
  605.                 self.scumlevel[user] += 500
  606.    
  607.     def someonescummy(self, user):
  608.         if user in self.scumlevel.keys():
  609.             print user+" is acting scummy and is going to be counted in self.scumlevel"
  610.             self.scumlevel[user] += 12
  611.             print self.scumlevel
  612.    
  613.     def massclaim(self, channel):
  614.         print 'massclaim central reached, what to do?'
  615.         if self.islylomylo == 'LYLO':
  616.             self.lyloaction(channel)
  617.         elif self.islylomylo == 'MYLO':
  618.             self.myloaction(channel)
  619.         else:
  620.             self.msg(channel, "It is not a time to massclaim, but to make you happy I'll just say I'm OC whether I actually am, or not")
  621.  
  622.     def mafiadayparser(self, channel, msg):
  623.         if msg.startswith("The following players are"):
  624.             self.makelivelist(msg)
  625.         elif msg.startswith("Darkness falls:"):
  626.             self.gametime = 'Night'
  627.             self.doneaction = False
  628.             self.nightnum += 1
  629.             print self.gametime, self.nightnum
  630.             self.nightaction(channel, msg)
  631.         elif msg.startswith('*** Examining the body'):
  632.             self.detduty(msg)
  633.         elif msg.startswith('The citizens may decide to lynch one player'):
  634.             print "we have to do something, it's lynching time (550)"
  635.             if self.islylomylo == 'LYLO':
  636.                 print "it is lylo im gonna claim, going to lyloaction"
  637.                 self.lyloaction(channel)
  638.             elif self.islylomylo == 'MYLO':
  639.                 print "it is mylo, gonna see what i should claim, going to myloaction"
  640.                 self.myloaction(channel)
  641.         elif msg.startswith('The majority has voted to lynch'):
  642.             self.newdie = msg.split(' ')[6][:-2]
  643.             print self.newdie+' is the newly dead'
  644.             if self.newdie in self.mafiafriendlist:
  645.                 self.mafiacount -= 1
  646.    
  647.     def scumnight(self, msg):
  648.         print "I'm going to do something scummy!"
  649.         if self.mafiacount == 1:
  650.             self.scumsolokill()        
  651.         elif len(self.mafiafriendlist) > 0:
  652.             print 'going to start mchat conversation'
  653.             self.msg(self.mafialeader, "mchat Alrighty then, let's get this started. Who do you think we should kill? I'll give you a little time to mull it over. Please use the following syntax:  kill <person>")
  654.             self.mchat1 = True
  655.             timedcall = len(self.mafiafriendlist) * 20
  656.             print self.mafiafriendlist
  657.             print '^ are my mafia friends'
  658.             return
  659.    
  660.     def scumsolokill(self):
  661.         if len(self.mafiafriendlist) == 0:
  662.             choose = self.alivelist
  663.             if self.nickname in choose:
  664.                 choose.remove(self.nickname)
  665.             killit = random.choice(choose)
  666.             print 'going to kill '+killit
  667.             self.msg(self.mafialeader, 'kill '+killit)
  668.         elif len(self.mafiacount) > 0:
  669.             self.mchat(msg)
  670.            
  671.     def mchat(self, msg):
  672.         print msg
  673.         msg = msg.split('>',1)[1].strip()
  674.         if self.mchat1:
  675.             if 'nokill' in msg:
  676.                 self.msg(self.mafialeader, "mchat Alright, so I hope everyone's agreed with the choice of a nokill, cause I'm voting for this choice.")
  677.                 self.msg(self.mafialeader, 'nokill')
  678.                 self.mchat1 = False
  679.                 print "mchatting done, sent a nokill"              
  680.             elif msg.startswith('kill') and len(msg.split(' ')) == 2:
  681.                 killit = msg.split(' ')[1]
  682.                 self.msg(self.mafialeader, "mchat Alright, so I hope everyone's agreed with the choice of %s to be killed, cause I'm voting for this choice." % killit)
  683.                 self.msg(self.mafialeader, "kill "+killit)
  684.                 self.mchat1 = False
  685.                 print "mchatting done, sent a kill for "+killit
  686.         else:      
  687.             return     
  688.            
  689.     def detduty(self, msg):
  690.         if self.sheeprole != 'det':
  691.             print 'reached detduty'
  692.             duty = msg.split(' ')[-1].strip('\x034').strip('\x0f!!').lower()
  693.             duty = duty.strip('.')
  694.             self.rolelist[self.newdie] = duty
  695.             for role in self.claimdict:
  696.                 if self.newdie in role:
  697.                     self.claimdict[role].remove(self.newdie)
  698.             print self.rolelist
  699.             if duty == 'mafia':
  700.                 self.mafiacount -= 1
  701.             if 'sheriff' in duty:
  702.                 self.iscop == False
  703.                 self.cop = self.newdie
  704.                 print self.cop+" has been registered as the COP I am going to remove this user from the scumlevel dict"
  705.                 if self.cop in self.claimdict['cop']:
  706.                     self.claimdict['cop'].remove(self.cop)
  707.                 if len(self.claimdict['cop']) > 0:
  708.                     for user in self.claimdict['cop']:
  709.                         self.scumlevel[user] += 400
  710.                 del self.claimdict['cop']
  711.             if 'doctor' in duty:
  712.                 self.isdoc == False
  713.                 self.doc = self.newdie
  714.                 if self.newdie in self.claimdict['doc']:
  715.                     del self.claimdict[self.newdie]
  716.                 print self.doc+" has been registered as the DOC I am going to remove this user from the scumlevel dict"
  717.                 if self.doc in self.claimdict['doc']:
  718.                     self.claimdict['doc'].remove(self.doc)
  719.                 if len(self.claimdict['doc']) > 0:
  720.                     for user in self.claimdict['doc']:
  721.                         self.scumlevel[user] += 400
  722.                 del self.claimdict['doc']
  723.             if 'detective' in duty:
  724.                 self.isdoc == False
  725.                 self.det = self.newdie
  726.                 if self.newdie in self.claimdict['det']:
  727.                     del self.claimdict[self.newdie]
  728.                 print self.det+" has been registered as the DET I am going to remove this user from the scumlevel dict"
  729.                 if self.det in self.claimdict:
  730.                     self.claimdict89['det'].remove(self.det)
  731.                 if len(self.claimdict['det']) > 0:
  732.                     for user in self.claimdict['det']:
  733.                         self.scumlevel[user] += 400
  734.                 del self.claimdict['det']
  735.                
  736.             if self.alreadyclaimed == False and 'normal' not in duty:
  737.                 print 'a PR died and need to check if my sheeprole might be a problem'
  738.                 if self.sheeprole == 'cop':
  739.                     if duty == 'sheriff':
  740.                         self.sheeprole = None
  741.                         self.sheeproller()
  742.                 elif self.sheeprole == 'doc':
  743.                     if duty == 'doctor':
  744.                         self.sheeprole = None
  745.                         self.sheeproller()
  746.                 elif self.sheeprole == 'det':
  747.                     if duty == 'detective':
  748.                         self.sheeprole = None
  749.                         self.sheeproller()
  750.         else:
  751.             print 'reached sheepdetduty'
  752.             if self.iscop == False:
  753.                 ran = random.randint(1,4)
  754.                 if ran == 1:
  755.                     self.rolelist[self.newdie] = 'doc'
  756.                 else:
  757.                     self.rolelist[self.newdie] == 'oc'
  758.             elif self.iscop and self.isdet == False:
  759.                 ran = random.randint(1,5)
  760.                 if ran == 1:
  761.                     self.rolelist[self.newdie] = 'doc'
  762.                 elif ran == 2:
  763.                     self.rolelist[self.newdie] = 'cop'
  764.                 else:
  765.                     self.rolelist[self.newdie] = 'oc'
  766.             elif self.isdoc and self.iscop and self.isdet:
  767.                 ran = random.randint(1, len(self.alivelist))
  768.                 if ran == 1:
  769.                     self.rolelist[self.newdie] = 'doc'
  770.                 elif ran == 2:
  771.                     self.rolelist[self.newdie] = 'cop'
  772.                 elif ran == 3:
  773.                     self.rolelist[self.newdie] = 'det'
  774.                 else:
  775.                     self.rolelist[self.newdie] = 'oc'
  776.         print self.newdie+" was a "+self.rolelist[self.newdie]
  777.            
  778.        
  779.    
  780.     def gamesetup(self):
  781.         print "Game started (figuring out types of roles)"
  782.         if len(self.alivelist) == 4:
  783.             print 'len of alive = 4'
  784.             self.isdoc = True
  785.             self.iscop = False
  786.             self.isdet = False
  787.         elif len(self.alivelist) == 5:
  788.             print 'len of alive = 5'
  789.             self.isdoc = True
  790.             self.iscop = True
  791.             self.isdet = False
  792.         elif len(self.alivelist) >= 6:
  793.             print 'len of alive >= 6'
  794.             self.isdoc = True
  795.             self.iscop = True
  796.             self.isdet = True
  797.         else:
  798.             print "something went wrong in gamesetup"
  799.    
  800.     def sheeproller(self):
  801.         if self.sheeprole == None:
  802.             for role in self.rolelist.values():
  803.                 if role.lower() == 'sheriff':
  804.                     self.iscop = False
  805.                 if role.lower() == 'detective':
  806.                     self.isdet == False
  807.                 if role.lower() == 'doctor':
  808.                     self.isdoc == False
  809.             if self.isdoc and self.iscop == False and self.isdet == False:
  810.                 ran = random.randint(1,2)
  811.                 if ran == 1:
  812.                     self.sheeprole = 'doc'
  813.                 elif ran == 2:
  814.                     self.sheeprole == 'oc'
  815.                 else:
  816.                     print 'sheeproler borked'
  817.             elif self.isdoc and self.iscop and self.isdet == False:
  818.                 ran = random.randint(1,3)
  819.                 if ran == 1:
  820.                     self.sheeprole = 'doc'
  821.                 elif ran == 2:
  822.                     self.sheeprole = 'cop'
  823.                 elif ran == 3:
  824.                     self.sheeprole = 'oc'
  825.                 else:
  826.                     print 'sheeproler borked'
  827.             elif self.isdoc and self.iscop and self.isdet:
  828.                 ran = random.randint(1, 4)
  829.                 if ran == 1:
  830.                     self.sheeprole = 'doc'
  831.                 elif ran == 2:
  832.                     self.sheeprole = 'cop'
  833.                 elif ran == 3:
  834.                     self.sheeprole = 'det'
  835.                 elif ran == 4:
  836.                     self.sheeprole = 'oc'
  837.                 else:
  838.                     print 'sheeprole borked'
  839.             elif self.isdoc == False and self.isdet and self.iscop:
  840.                 ran = random.randint(1,3)
  841.                 if ran == 2:
  842.                     self.sheeprole = 'cop'
  843.                 elif ran == 3:
  844.                     self.sheeprole = 'det'
  845.                 elif ran == 1:
  846.                     self.sheeprole = 'oc'
  847.                 else:
  848.                     print 'sheeprole borked'
  849.             elif self.isdoc == False and self.iscop == False and self.isdet:
  850.                 ran = random.randint(1,2)
  851.                 if ran == 2:
  852.                     self.sheeprole = 'det'
  853.                 elif ran == 1:
  854.                     self.sheeprole = 'oc'
  855.                 else:
  856.                     print 'sheeprole borked'
  857.             elif self.isdoc == False and self.isdet == False and self.iscop:
  858.                 ran = random.randint(1,2)
  859.                 if ran == 2:
  860.                     self.sheeprole = 'cop'
  861.                 elif ran == 1:
  862.                     self.sheeprole = 'oc'
  863.                 else:
  864.                     print 'sheeprole borked'
  865.             else:
  866.                 self.sheeprole = 'oc'              
  867.         print "MY SHEEPROLE IS: "+self.sheeprole
  868.        
  869.     def sheriffday(self, channel):
  870.         print "sheriffday"
  871.         isit = False
  872.         guiltylist = []
  873.         innocentlist = []
  874.         if len(self.maflist) > 0:
  875.             for night in self.maflist:
  876.                 guiltylist.append(" checked %s night %d" % (self.maflist[night], self.nightnum))
  877.             copguiltreplist = ', '.join(copguiltreplist)
  878.             print copguiltreplist
  879.             copposchoice = random.choice(self.coppos)
  880.             self.msg(channel, (copposchoice,copguiltreplist))
  881.         if len(self.innolist) > 0:
  882.             for user in self.innolist:
  883.                 if user in self.scumlevel.keys():
  884.                     del self.scumlevel[user]
  885.             for night in self.innolist:
  886.                 copinnoreplist.append(" checked %s night %d" % (self.maflist[night], night))
  887.             copinnoreplist = ', '.join(copinnoreplist)
  888.             print copinnoreplist
  889.             copinnochoice = random.choice(self.copinno)
  890.             self.msg(channel, (copinnochoice, copinnoreplist))
  891.         self.alreadyclaimed = True
  892.        
  893.     def detectiveday(self, channel):
  894.         print "detectiveday"
  895.         followedreport = []
  896.         for person in self.rolelist:
  897.             followedreport.append(" %s was a %s" % (person, self.rolelist[person]))
  898.         followedreport = ', '.join(followedreport)
  899.         detchoice = random.choice(self.detness)
  900.         self.msg(channel, (detchoice, followedreport))
  901.        
  902.     def docday(self, channel):
  903.         print "docday"
  904.         savedreport = []
  905.         for person in self.saveddict:
  906.             savedreport.append(" saved %s night %d" % (person, self.rolelist[person]))
  907.         savedreport = ', '.join(savedreport)
  908.         docchoice = random.choice(self.docsave)
  909.         self.msg(channel, (docchoice, savedreport))
  910.            
  911.     def lynchscummiest(self, user, channel):
  912.         self.scumlevel[user] += 10 
  913.         topscummy = {}
  914.         for player, scumlevel in self.scumlevel.iteritems():
  915.             if scumlevel not in topscummy:
  916.                 topscummy[scumlevel] = []
  917.             topscummy[scumlevel].append(player)
  918.         if len(self.claimdict['cop']) > 1 and self.alreadylynch == False:
  919.             choice = random.choice(self.claimdict['cop'])
  920.             self.msg(channel, "I choose this cop claim to be mafia!")
  921.             self.msg(channel, "!lynch "+choice)
  922.             self.alreadylynch = True
  923.             return
  924.         elif len(self.claimdict['doc']) > 1 and self.alreadylynch == False:
  925.             choice = random.choice(self.claimdict['doc'])
  926.             self.msg(channel, "I choose this doc claim to be mafia!")
  927.             self.msg(channel, "!lynch "+choice)
  928.             self.alreadylynch = True
  929.             return
  930.         elif len(self.claimdict['det']) > 1 and self.alreadylynch == False:
  931.             choice = random.choice(self.claimdict['det'])
  932.             self.msg(channel, "I choose this det claim to be mafia!")
  933.             self.msg(channel, "!lynch "+choice)
  934.             self.alreadylynch = True
  935.             return
  936.         else:
  937.             print topscummy
  938.             sortedscummy = sorted(topscummy.iteritems(), reverse=True, key=lambda n:n[0])
  939.             print sortedscummy[0][1][0]
  940.             print '^ is the scummiest in my eyes'
  941.             topscumbag = sortedscummy[0][1][0]
  942.             if self.topscum != topscumbag:
  943.                 self.topscum = topscumbag
  944.                 explain = random.choice(self.explainlynchscum)
  945.                 self.msg(channel, explain)
  946.                 self.msg(channel, '!lynch '+self.topscum)
  947.                 self.doneaction = True
  948.             elif self.topscum == topscumbag:
  949.                 alreadydone = random.choice(self.alreadylynched)
  950.                 self.msg(channel, alreadydone)
  951.             else:
  952.                 alreadydone = random.choice(self.alreadylynched)
  953.                 self.msg(channel, alreadydone)
  954.            
  955.        
  956.        
  957. class KomurinFactory(protocol.ClientFactory):       #A 'factory' for the bot.
  958.     protocol = Komurin
  959.  
  960.     def __init__(self, channel):
  961.         self.channel = channel
  962.  
  963.     def clientConnectionLost(self, connector, reason):      #We got disconnected, reconnect.
  964.         connector.connect()
  965.        
  966.  
  967.     def clientConnectionFailed(self, connector, reason):
  968.         print "connection failed:", reason
  969.         reactor.stop()
  970.  
  971.  
  972. if __name__ == '__main__':                              #Check if we ran it, not imported it.
  973.     dev = '#mafia-testing'
  974.     chan = '#mafia'
  975.     #global debug
  976.    
  977.     if debug:
  978.         f = KomurinFactory(dev)                         #No spaces between channels
  979.     else:
  980.         f = KomurinFactory(chan)
  981.  
  982.     reactor.connectTCP("irc.foonetic.net", 6667, f)     #Connect the factory to the network.
  983.  
  984.     reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement