Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # this bot better beat You and Younata! :P
- # todo: fix counterclaims after a person is already chosen as a PR | better telling if a person is claiming | specify nokill in the mchat
- import random, re, time, threading
- from itertools import *
- from twisted.words.protocols import irc
- from twisted.internet import reactor, protocol, task, defer
- global debug
- debug = True
- class Komurin(irc.IRCClient):
- def __init__(self):
- self.nickname = "Trinity"
- self.password = ""
- self.version = "1.0.0"
- self.trigger = "-"
- self.ubertrigger = "-"
- if debug == False:
- self.mafialeader = 'Siobhan'
- self.mafiaroom = '#mafia'
- self.autojoin = False
- else:
- self.mafialeader = 'MafiaTester'
- self.mafiaroom = '#mafia-testing'
- self.autojoin = True
- #game specific starting option
- self.ingame = False
- self.daynum = 0
- self.nightnum = 0
- self.gametime = None
- self.alivelist = []
- self.deadlist = []
- self.sheeprole = None
- self.mafiafriendlist = []
- self.havemchatted = False
- self.rolelist = {}
- self.newdie = "None"
- self.doneaction = False
- self.claimdict = {}
- self.claimdict['doc'] = []
- self.claimdict['cop'] = []
- self.claimdict['det'] = []
- self.claimdict['oc'] = []
- self.saveddict = {}
- self.scumlevel = {}
- self.topscum = None
- self.doc = None
- self.det = None
- self.cop = None
- self.gamesetdid = False
- self.claimeddoc = False
- self.claimeddet = False
- self.claimedcop = False
- #responses
- 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:"]
- self.copposrep = " checked %s night %d"
- 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"]
- self.copinnorep = " checked %s night %d"
- self.docsave = ["I'm doc!", "Might be a mistake, but, ya, I'm doc.", "Doc here!", "Bitch, I'm the DOC,"]
- self.docsaverep = " saved %s night %d"
- self.detness = ["Ya, I'm detective.","Guess it's time to reveal myself, I'm detective.", "<--Detective "]
- self.detrep = " %s was a %s"
- 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!"]
- 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"]
- 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!"]
- self.nlarg = ["I dont want to take the risk of an rl right now :/", "RL is the path to the fail side"]
- 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!"]
- 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"]
- 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..."]
- 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"]
- self.scumalias = "(scum|mafia|maf|scummy|scumbuddies|guilty)"
- self.notinmsg = "(nt|n't|no|any|\?|who|what|how|where|other|she|he|someone|else|it|keep|either|or|is|over here)"
- self.docalias = "(doc|doctor|medic|med|phd)"
- self.copalias = "(cop|sheriff|police|popo|fuzz)"
- self.detalias = "(det|detective|mort|mortician|deticitive)"
- self.claiming = "(<|i'm|im|i am)"
- 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)"
- self.decidethis = "(decide|think|what|do you|who|sure)"
- self.copfoundscum = "(is scum|is mafia|lynch)"
- def connectionMade(self):
- irc.IRCClient.connectionMade(self)
- def connectionLost(self, reason):
- print("LOST CONNECTION! REASON: %s" % reason)
- irc.IRCClient.connectionLost(self, reason)
- reactor.start()
- def signedOn(self):
- self.join(self.factory.channel)
- self.mode(self.nickname, True, '+B', limit=None, user=self.nickname)
- print('Joined irc.foonetic.net as %s' %(self.nickname))
- def joined(self, channel):
- print('Joined %s' %(channel))
- self.me(channel, 'version '+self.version)
- def noticed(self, user, channel, msg):
- user = user.split('!', 1)[0]
- if user == self.mafialeader:
- print '<%s> %s' % (user, msg)
- self.msgparser(user, channel, msg)
- def privmsg(self, user, channel, msg):
- user = user.split('!', 1)[0]
- msg = msg.rstrip()
- if self.ingame:
- self.msgparser(user, channel, msg)
- elif msg.startswith("A new game has begun!") and user == self.mafialeader:
- print 'game has begun!'
- self.ingame = True
- self.daynum = 0
- self.nightnum = 0
- self.gametime = None
- #put ingame variables here
- self.isdoc = False
- self.iscop = False
- self.isdet = False
- self.doc = None
- self.det = None
- self.cop = None
- self.maflist = {}
- self.innolist = {}
- self.alivelist = []
- self.deadlist = []
- self.sheeprole = None
- self.mafiafriendlist = []
- self.havemchatted = False
- self.rolelist = {}
- self.newdie = 'None'
- self.doneaction = False
- self.claimdict = {}
- self.claimdict['doc'] = []
- self.claimdict['cop'] = []
- self.claimdict['det'] = []
- self.claimdict['oc'] = []
- self.saveddict = {}
- self.scumlevel = {}
- self.topscum = None
- self.gamesetdid = False
- self.claimeddoc = False
- self.claimeddet = False
- self.claimedcop = False
- else:
- if msg == self.trigger + 'autojoin.off':
- self.autojoin = False
- self.msg(channel, 'Autojoin is OFF')
- elif msg == self.trigger + 'autojoin.on':
- self.autojoin = True
- self.msg(channel, 'Autojoin is ON')
- elif msg == self.trigger + 'autojoin':
- self.msg(channel, 'Autojoin is %s' % self.autojoin)
- elif msg.startswith(self.trigger+'join') and channel == self.mafiaroom:
- self.msg(channel, '!join')
- elif msg.startswith(self.trigger+'quit') and channel == self.mafiaroom:
- self.msg(channel, '!quit')
- elif msg.startswith('A new game has been started by') and self.autojoin:
- self.msg(channel, '!join')
- def msgparser(self, user, channel, msg):
- #print "reached msgparser at this: "+msg
- if msg == ("The game has ended.") and self.ingame:
- self.ingame = False
- print "Game has ended"
- elif msg.startswith('Mafia - <'):
- print "recieved a mchat message"
- self.mchat(msg)
- elif self.gametime == 'Day':
- self.daymsgparser(user, channel, msg)
- elif self.gametime == 'Night' or self.gametime == None:
- self.nightmsgparser(user, channel, msg)
- def nightmsgparser(self, user, channel, msg):
- #print "reached nightmsgparser at this: "+msg
- if user == self.mafialeader:
- self.mafianightparser(channel, msg)
- def mafianightparser(self, channel, msg):
- #print 'reached mafianightparser at '+msg
- if msg.startswith("You're a"):
- print 'identified a role giving'
- self.roleparser(msg)
- elif msg.startswith("Darkness falls:"):
- self.gametime = 'Night'
- self.nightnum += 1
- print self.gametime, self.nightnum
- self.nightaction(channel, msg)
- self.alreadyclaimed = False
- self.doneaction = False
- elif "Sunlight pierces the sky" in msg:
- self.alreadyclaimed = False
- self.alreadylynch = False
- self.doneaction = False
- self.gametime = 'Day'
- self.daynum += 1
- print self.gametime, self.daynum
- if "Noone was killed." in msg:
- self.msg(channel, "doc++")
- self.newdie = 'None'
- elif "mutilated body of" in msg:
- self.msg(channel, "doc--")
- dead = msg.split(' ')[-1]
- dead = dead.strip('\x034').strip('\x0f!!')
- print dead+' is dead :/'
- self.newdie = dead
- if self.newdie in self.mafiafriendlist:
- self.mafiacount -= 1
- elif msg.startswith("The following players are"):
- self.makelivelist(msg)
- elif msg == "There is only one Mafia.":
- self.mafiacount = 1
- print '1 mafia'
- elif msg.startswith('There are') and msg.split(' ')[3] == 'Mafia.':
- self.mafiacount = int(msg.split(' ')[2])
- print str(self.mafiacount)+' mafia'
- elif msg.startswith('The Mafia are'):
- print msg
- self.mafiafriendlist = []
- parsedmaf = msg.split('are ',1)[1].split('.',1)[0].strip().split(', ')
- self.mafiafriendlist.append(parsedmaf)
- self.scumnight(msg)
- def nightaction(self, channel, msg):
- print "Alright, going to do an action of some sort. nightaction reached"
- if self.role == 'COP' or self.sheeprole == 'cop':
- print "going to do something as a cop"
- if self.role == 'COP':
- #choice = None
- print 'self.maflist:'
- print self.maflist
- print 'self.innolist:'
- print self.innolist
- alreadycheckedlist = self.maflist.values()+self.innolist.values()
- checklist = filter(lambda n: n not in alreadycheckedlist, self.alivelist)
- #while choice == self.nickname or choice == None or choice in self.maflist or choice in self.innolist:
- # choice = random.choice(self.alivelist)
- print checklist
- try:
- choice = random.choice(checklist)
- except IndexError:
- print 'INDEX ERROR ' * 5
- choice = random.choice(checklist)
- self.msg(self.mafialeader, "check "+choice)
- self.checked = choice
- print 'checked '+choice
- elif self.role == 'SCUM' and self.sheeprole == 'cop':
- sheepchoice = None
- alreadycheckedlist = self.maflist+self.innolist
- checklist = filter(lambda n: n not in self.alivelist, alreadycheckedlist)
- checklist.remove(self.nickname)
- while sheepchoice in self.maflist or sheepchoice in self.innolist or sheepchoice == self.nickname or sheepchoice == None:
- sheepchoice = random.choice(checklist)
- sheepchoice = random.choice(checklist)
- if random.randint(1,3) == 1 and self.mafcount > len(self.maflist):
- self.maflist[self.nightnum] = sheepchoice
- else:
- self.innolist[self.nightnum] = sheepchoice
- if sheepchoice in self.scumlevel.keys():
- del self.scumlevel[sheepchoice]
- self.checked = sheepchoice
- print 'scumchecked '+ sheepchoice
- self.scumnight(msg)
- elif self.role == 'DOC' or self.sheeprole == 'doc':
- print 'gonna do something as doc'
- if self.role == 'DOC':
- choice = None
- while choice == self.nickname or choice == None:
- choice = random.choice(self.alivelist)
- self.msg(self.mafialeader, "save "+choice)
- self.saved = choice
- self.saveddict[self.nightnum] = choice
- print 'saved '+choice
- elif self.role == 'SCUM' and self.sheeprole == 'doc':
- sheepchoice = None
- while sheepchoice == self.nickname or sheepchoice == None:
- sheepchoice = random.choice(self.alivelist)
- self.saved = sheepchoice
- self.saveddict[self.nightnum] = sheepchoice
- print 'scumsaved '+sheepchoice
- self.scumnight(msg)
- elif self.role == 'SCUM':
- self.scumnight(msg)
- else:
- return
- def makelivelist(self, msg):
- if msg.startswith("The following players are still alive:"):
- self.alivelist = []
- self.alivelist = msg.split(':',1)[1].strip().split(', ')
- print 'i got an alivelist '
- print self.alivelist
- for user in self.alivelist:
- if user not in self.scumlevel.keys():
- self.scumlevel[user] = 0
- print self.scumlevel
- if self.gamesetdid == False:
- self.gamesetup()
- self.gamesetdid = True
- if self.role == 'SCUM':
- self.sheeproller()
- elif msg.startswith("The following players are dead :"):
- self.deadlist = []
- self.deadlist = msg.split(':',1)[1].strip().split(', ')
- print 'i got a deadlist '
- print self.deadlist
- for user in self.deadlist:
- if user in self.scumlevel.keys():
- del self.scumlevel[user]
- print self.scumlevel
- self.lylomylo()
- def lylomylo(self):
- x = 0
- mafnum = self.mafiacount
- for role in self.rolelist.values():
- if role.lower == 'mafia':
- mafnum -= 1
- number = len(self.alivelist) - mafnum
- if number == mafnum + 1:
- self.islylomylo = 'LYLO'
- elif number == mafnum + 2:
- self.islylomylo = 'MYLO'
- else:
- self.islylomylo = 'NONE'
- print 'IT IS '+self.islylomylo
- def lyloaction(self, channel):
- print 'reached lyloaction'
- ran = random.randint(5,13)
- time.sleep(ran)
- randomlylochoice = random.choice(self.lyloreason)
- self.msg(channel, randomlylochoice)
- if self.role == 'COP' or self.sheeprole == 'cop':
- print 'going to sheriffday'
- self.sheriffday(channel)
- if len(self.maflist) > 0 and self.doneaction == False:
- choice = random.choice(self.maflist)
- self.msg(channel, '!lynch '+choice)
- self.doneaction = True
- else:
- if self.doneaction == False:
- choice = filter(lambda n: n not in self.alivelist, self.innolist)
- self.msg(channel, '!lynch '+choice)
- self.doneaction = True
- elif self.role == 'DOC' or self.sheeprole == 'doc':
- print 'going to docday'
- self.docday(channel)
- elif self.role == 'DET' or self.sheeprole == 'det':
- print 'going to detectiveday'
- self.detectiveday(channel)
- else:
- print 'doing my oc thing'
- occhoice = random.choice(self.ocrep)
- self.msg(channel, occhoice)
- self.alreadyclaimed = True
- def myloaction(self, channel):
- print 'reached myloaction'
- ran = random.randint(5,13)
- time.sleep(ran)
- if self.role == 'OC' or self.sheeprole == 'oc' or self.role == 'DOC' or self.sheeprole == 'doc':
- print "doing my oc thing"
- occhoice = random.choice(self.ocrep)
- self.msg(channel, occhoice)
- if len(self.maflist) > 0:
- if self.alreadyclaimed == False:
- self.sheriffday(channel)
- if len(self.maflist) > 0 and self.doneaction == False:
- choice = random.choice(self.maflist)
- self.msg(channel, '!lynch '+choice)
- self.doneaction = True
- else:
- if self.doneaction == False:
- choice = filter(lambda n: n not in self.alivelist, self.innolist)
- self.msg(channel, '!lynch '+choice)
- self.doneaction = True
- self.alreadyclaimed = True
- return
- randommylochoice = random.choice(self.myloarg)
- self.msg(channel, randommylochoice)
- self.msg(channel, '!nolynch')
- def roleparser(self, msg):
- #print 'reached mafiaroleparser'
- if 'sheriff' in msg.lower():
- self.role = 'COP'
- print 'I am cop'
- elif 'doctor' in msg.lower():
- self.role = 'DOC'
- self.savedlist = []
- print 'I am doc'
- elif 'detective' in msg.lower():
- self.role = 'DET'
- print 'I am det'
- elif 'mafia' in msg.lower():
- self.role = "SCUM"
- print 'I am scum'
- elif 'citizen' in msg.lower() and not 'mafia' in msg.lower():
- self.role = 'OC'
- print 'I am OC'
- else:
- print "something went wacky in the roleparsing, I can't find any role i'm in"
- def daymsgparser(self, user, channel, msg):
- #print "reached daymsgparser"
- if user == self.mafialeader:
- self.mafiadayparser(channel, msg)
- else:
- self.mafiauserparser(user, channel, msg)
- def mafiauserparser(self, user, channel, msg):
- print 'reached mafiauserparser'
- if user == self.cop and re.search(self.copfoundscum, msg.lower()):
- for user in self.alivelist:
- if user.lower() in msg.lower() and user != self.cop:
- self.scumlevel[user] += 600
- if user in self.alivelist:
- self.scumlevel[user] += 1
- if re.search(self.scummystuff, msg.lower()):
- print 'someone is acting scummier than usual!'
- self.someonescummy(user)
- if user == self.cop and 'is' in msg and 'scum' in msg:
- print 'sheriff claimed going to sheriffclaimed()'
- self.sheriffclaimed()
- if 'massclaim' in msg.lower() and re.search(self.notinmsg, msg.lower()):
- print 'someone is calling for a massclaim'
- self.massclaim(channel)
- if re.search(self.decidethis, msg.lower()) and self.username.lower() in msg.lower():
- print "I'm being asked to decide the fate of someone!"
- self.lynchscummiest(user, channel)
- if self.nickname in msg:
- if self.islylomylo == 'LYLO':
- if msg.lower().strip() == '!lynch trinity':
- self.lynchingmelylo
- elif msg.lower().strip() == '!nolynch':
- self.msg(channel, "WHOA scum alert! You don't nolynch on lylo! %s's definitely a mafia." % user)
- self.scumlevel[user] += 190
- print self.scumlevel
- elif msg.lower().strip() == '!lynch trinity':
- choice = random.choice(self.notmafia)
- self.msg(channel, choice)
- self.scumlevel[user] += 100
- print self.scumlevel
- else:
- if not re.search(self.notinmsg, msg.lower()) and re.search(self.scumalias, msg.lower()):
- print "someone be calling me scum!"
- randomchoice = random.choice(self.notmafia)
- self.msg(channel, randomchoice)
- self.scumlevel[user] += 40
- print self.scumlevel
- if not re.search(self.notinmsg, msg.lower()) and re.search(self.claiming, msg.lower()):
- print 'testing for claim'
- 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:
- self.checkrole(user, channel, msg)
- elif not re.search(self.notinmsg, msg.lower()) and re.search(self.docalias, msg.lower()) and re.search(self.claiming, msg.lower()):
- if user in self.claimdict['cop'] or user in self.claimdict['det'] or self.isdoc == False:
- print 'print someone is trying to claim that they are doc when they arent'
- self.msg(channel, 'Whoa, %s, you already claimed as something else!' % user)
- self.scumlevel[user] += 45
- elif not re.search(self.notinmsg, msg.lower()) and re.search(self.copalias, msg.lower()) and re.search(self.claiming, msg.lower()):
- if user in self.claimdict['doc'] or user in self.claimdict['det'] or self.iscop == False:
- print 'print someone is trying to claim that they are cop when they arent'
- self.msg(channel, 'Whoa, %s, you already claimed as something else!' % user)
- self.scumlevel[user] += 45
- elif not re.search(self.notinmsg, msg.lower()) and re.search(self.detalias, msg.lower()) and re.search(self.claiming, msg.lower()):
- if user in self.claimdict['doc'] or user in self.claimdict['cop'] or self.isdet == False:
- print 'print someone is trying to claim that they are det when they arent'
- self.msg(channel, 'Whoa, %s, you already claimed as something else!' % user)
- self.scumlevel[user] += 45
- def checkrole(self, user, channel, msg):
- print "so far so good user has not previously claimed"
- if re.search(self.docalias, msg.lower()) and self.isdoc == True:
- print 'person is trying to claim doc'
- if self.role == 'DOC' or self.sheeprole == 'doc':
- print "someone is trying to claim my doc role!"
- print 'going to docday'
- self.docday(channel)
- self.maflist.append(user)
- self.msg(channel, '!lynch '+user)
- self.doneaction = True
- print self.maflist
- role = 'doc'
- else:
- print "registering user as doctor claim"
- self.claimdict['doc'].append(user)
- print self.claimdict
- print "starting timer for doc"
- self.claimeddoc = True
- doctoclaim = threading.Timer(30, self.claimfinalize)
- self.msg(channel, 'Alright %s claimed doc, anyone gonna cc?' % user)
- doctoclaim.start()
- elif re.search(self.copalias, msg.lower()) and self.isdoc == True:
- print 'person is trying to claim cop'
- if self.role == 'COP' or self.sheeprole == 'cop':
- print 'someone is trying to claim my cop role!'
- print 'going to sheriffday'
- self.sheriffday(channel)
- self.maflist['day'+str(self.daynum)] = user
- self.msg(channel, '!lynch '+user)
- self.doneaction = True
- print self.maflist
- else:
- print "registering user as sheriff claim"
- self.claimdict['cop'].append(user)
- print self.claimdict
- print 'gonna try the timeout'
- self.claimedcop = True
- coptoclaim = threading.Timer(30, self.claimfinalize)
- self.msg(channel, 'Alright %s claimed cop, anyone gonna cc?' % user)
- coptoclaim.start()
- elif re.search(self.detalias, msg.lower()) and self.isdet == True:
- print 'person is trying to claim det'
- if self.role == 'DET' or self.sheeprole == 'det':
- print 'someone is trying to claim my det role!'
- print 'going to detectiveday'
- self.detectiveday(channel)
- self.maflist.append(user)
- sefl.msg(channel, '!lynch '+user)
- self.doneaction = True
- print self.maflist
- else:
- print 'registering user as det claim'
- self.claimdict['det'].append(user)
- print self.claimdict
- print 'gonna try the timeout'
- self.claimeddet = True
- dettoclaim = threading.Timer(30, self.claimfinalize)
- self.msg(channel, 'Alright %s claimed det, anyone gonna cc?' % user)
- dettoclaim.start()
- def claimfinalize(self, args=[], kwargs={}):
- print 'inclaimfinalize'
- if self.claimeddoc:
- if len(self.claimdict['doc']) == 1:
- self.doc = self.claimdict['doc'][0]
- print self.doc+" has been registered as the DOC I am going to remove this user from the scumlevel dict"
- self.scumlevel[self.doc] -= 100000000000000
- self.claimeddoc = False
- self.msg(channel, self.doc+' is cleared in my book')
- elif self.claimedcop:
- if len(self.claimdict['cop']) == 1:
- self.cop = self.claimdict['cop'][0]
- print self.cop+" has been registered as the COP I am going to remove this user from the scumlevel dict"
- self.scumlevel[self.cop] -= 100000000000000
- self.claimedcop = False
- self.msg(channel, self.cop+' is cleared in my book')
- elif self.claimeddet:
- if len(self.claimdict['det']) == 1:
- self.det = self.claimdict['det'][0]
- print self.det+" has been registered as the DET I am going to remove this user from the scumlevel dict"
- self.scumlevel[self.det] -= 100000000000000
- self.claimeddet = False
- self.msg(channel, self.cop+' is cleared in my book')
- def lynchingmelylo(self, channel):
- self.scumlevel[user]+=20
- print self.scumlevel
- print 'someone tried lyching me during lylo, HOW DARE THEY - 1'
- print 'going to tell them my role before i lynch them back - 2'
- if self.doneaction == False:
- if self.role == 'COP' or self.sheeprole == 'cop':
- print 'going to sheriffday'
- self.sheriffday(channel)
- if len(self.maflist) > 0 and self.doneaction == False:
- choice = random.choice(self.maflist)
- self.msg(channel, '!lynch '+choice)
- self.doneaction = True
- else:
- if self.doneaction == False:
- choice = filter(lambda n: n not in self.alivelist, self.innolist)
- self.msg(channel, '!lynch '+choice)
- self.doneaction = True
- elif self.role == 'DOC' or self.sheeprole == 'doc':
- print 'going to docday'
- self.docday(channel)
- self.msg(channel, '!lynch '+choice)
- self.doneaction = True
- elif self.role == 'DET' or self.sheeprole == 'det':
- print 'going to detectiveday'
- self.detectiveday(channel)
- self.msg(channel, '!lynch '+choice)
- self.doneaction = True
- else:
- print 'doing my oc thing'
- occhoice = random.choice(self.ocrep)
- self.msg(channel, occhoice)
- self.msg(channel, '!lynch '+choice)
- self.doneaction = True
- self.alreadyclaimed = True
- def sheriffclaimed(self):
- turkey = msg.split(' ')
- print 'the confirmed cop is saying that someone is mafia!'
- for user in self.alivelist:
- if user in turkey:
- print user+' is apparently mafia!'
- self.scumlevel[user] += 500
- def someonescummy(self, user):
- if user in self.scumlevel.keys():
- print user+" is acting scummy and is going to be counted in self.scumlevel"
- self.scumlevel[user] += 12
- print self.scumlevel
- def massclaim(self, channel):
- print 'massclaim central reached, what to do?'
- if self.islylomylo == 'LYLO':
- self.lyloaction(channel)
- elif self.islylomylo == 'MYLO':
- self.myloaction(channel)
- else:
- 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")
- def mafiadayparser(self, channel, msg):
- if msg.startswith("The following players are"):
- self.makelivelist(msg)
- elif msg.startswith("Darkness falls:"):
- self.gametime = 'Night'
- self.doneaction = False
- self.nightnum += 1
- print self.gametime, self.nightnum
- self.nightaction(channel, msg)
- elif msg.startswith('*** Examining the body'):
- self.detduty(msg)
- elif msg.startswith('The citizens may decide to lynch one player'):
- print "we have to do something, it's lynching time (550)"
- if self.islylomylo == 'LYLO':
- print "it is lylo im gonna claim, going to lyloaction"
- self.lyloaction(channel)
- elif self.islylomylo == 'MYLO':
- print "it is mylo, gonna see what i should claim, going to myloaction"
- self.myloaction(channel)
- elif msg.startswith('The majority has voted to lynch'):
- self.newdie = msg.split(' ')[6][:-2]
- print self.newdie+' is the newly dead'
- if self.newdie in self.mafiafriendlist:
- self.mafiacount -= 1
- def scumnight(self, msg):
- print "I'm going to do something scummy!"
- if self.mafiacount == 1:
- self.scumsolokill()
- elif len(self.mafiafriendlist) > 0:
- print 'going to start mchat conversation'
- 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>")
- self.mchat1 = True
- timedcall = len(self.mafiafriendlist) * 20
- print self.mafiafriendlist
- print '^ are my mafia friends'
- return
- def scumsolokill(self):
- if len(self.mafiafriendlist) == 0:
- choose = self.alivelist
- if self.nickname in choose:
- choose.remove(self.nickname)
- killit = random.choice(choose)
- print 'going to kill '+killit
- self.msg(self.mafialeader, 'kill '+killit)
- elif len(self.mafiacount) > 0:
- self.mchat(msg)
- def mchat(self, msg):
- print msg
- msg = msg.split('>',1)[1].strip()
- if self.mchat1:
- if 'nokill' in msg:
- 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.")
- self.msg(self.mafialeader, 'nokill')
- self.mchat1 = False
- print "mchatting done, sent a nokill"
- elif msg.startswith('kill') and len(msg.split(' ')) == 2:
- killit = msg.split(' ')[1]
- 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)
- self.msg(self.mafialeader, "kill "+killit)
- self.mchat1 = False
- print "mchatting done, sent a kill for "+killit
- else:
- return
- def detduty(self, msg):
- if self.sheeprole != 'det':
- print 'reached detduty'
- duty = msg.split(' ')[-1].strip('\x034').strip('\x0f!!').lower()
- duty = duty.strip('.')
- self.rolelist[self.newdie] = duty
- for role in self.claimdict:
- if self.newdie in role:
- self.claimdict[role].remove(self.newdie)
- print self.rolelist
- if duty == 'mafia':
- self.mafiacount -= 1
- if 'sheriff' in duty:
- self.iscop == False
- self.cop = self.newdie
- print self.cop+" has been registered as the COP I am going to remove this user from the scumlevel dict"
- if self.cop in self.claimdict['cop']:
- self.claimdict['cop'].remove(self.cop)
- if len(self.claimdict['cop']) > 0:
- for user in self.claimdict['cop']:
- self.scumlevel[user] += 400
- del self.claimdict['cop']
- if 'doctor' in duty:
- self.isdoc == False
- self.doc = self.newdie
- if self.newdie in self.claimdict['doc']:
- del self.claimdict[self.newdie]
- print self.doc+" has been registered as the DOC I am going to remove this user from the scumlevel dict"
- if self.doc in self.claimdict['doc']:
- self.claimdict['doc'].remove(self.doc)
- if len(self.claimdict['doc']) > 0:
- for user in self.claimdict['doc']:
- self.scumlevel[user] += 400
- del self.claimdict['doc']
- if 'detective' in duty:
- self.isdoc == False
- self.det = self.newdie
- if self.newdie in self.claimdict['det']:
- del self.claimdict[self.newdie]
- print self.det+" has been registered as the DET I am going to remove this user from the scumlevel dict"
- if self.det in self.claimdict:
- self.claimdict89['det'].remove(self.det)
- if len(self.claimdict['det']) > 0:
- for user in self.claimdict['det']:
- self.scumlevel[user] += 400
- del self.claimdict['det']
- if self.alreadyclaimed == False and 'normal' not in duty:
- print 'a PR died and need to check if my sheeprole might be a problem'
- if self.sheeprole == 'cop':
- if duty == 'sheriff':
- self.sheeprole = None
- self.sheeproller()
- elif self.sheeprole == 'doc':
- if duty == 'doctor':
- self.sheeprole = None
- self.sheeproller()
- elif self.sheeprole == 'det':
- if duty == 'detective':
- self.sheeprole = None
- self.sheeproller()
- else:
- print 'reached sheepdetduty'
- if self.iscop == False:
- ran = random.randint(1,4)
- if ran == 1:
- self.rolelist[self.newdie] = 'doc'
- else:
- self.rolelist[self.newdie] == 'oc'
- elif self.iscop and self.isdet == False:
- ran = random.randint(1,5)
- if ran == 1:
- self.rolelist[self.newdie] = 'doc'
- elif ran == 2:
- self.rolelist[self.newdie] = 'cop'
- else:
- self.rolelist[self.newdie] = 'oc'
- elif self.isdoc and self.iscop and self.isdet:
- ran = random.randint(1, len(self.alivelist))
- if ran == 1:
- self.rolelist[self.newdie] = 'doc'
- elif ran == 2:
- self.rolelist[self.newdie] = 'cop'
- elif ran == 3:
- self.rolelist[self.newdie] = 'det'
- else:
- self.rolelist[self.newdie] = 'oc'
- print self.newdie+" was a "+self.rolelist[self.newdie]
- def gamesetup(self):
- print "Game started (figuring out types of roles)"
- if len(self.alivelist) == 4:
- print 'len of alive = 4'
- self.isdoc = True
- self.iscop = False
- self.isdet = False
- elif len(self.alivelist) == 5:
- print 'len of alive = 5'
- self.isdoc = True
- self.iscop = True
- self.isdet = False
- elif len(self.alivelist) >= 6:
- print 'len of alive >= 6'
- self.isdoc = True
- self.iscop = True
- self.isdet = True
- else:
- print "something went wrong in gamesetup"
- def sheeproller(self):
- if self.sheeprole == None:
- for role in self.rolelist.values():
- if role.lower() == 'sheriff':
- self.iscop = False
- if role.lower() == 'detective':
- self.isdet == False
- if role.lower() == 'doctor':
- self.isdoc == False
- if self.isdoc and self.iscop == False and self.isdet == False:
- ran = random.randint(1,2)
- if ran == 1:
- self.sheeprole = 'doc'
- elif ran == 2:
- self.sheeprole == 'oc'
- else:
- print 'sheeproler borked'
- elif self.isdoc and self.iscop and self.isdet == False:
- ran = random.randint(1,3)
- if ran == 1:
- self.sheeprole = 'doc'
- elif ran == 2:
- self.sheeprole = 'cop'
- elif ran == 3:
- self.sheeprole = 'oc'
- else:
- print 'sheeproler borked'
- elif self.isdoc and self.iscop and self.isdet:
- ran = random.randint(1, 4)
- if ran == 1:
- self.sheeprole = 'doc'
- elif ran == 2:
- self.sheeprole = 'cop'
- elif ran == 3:
- self.sheeprole = 'det'
- elif ran == 4:
- self.sheeprole = 'oc'
- else:
- print 'sheeprole borked'
- elif self.isdoc == False and self.isdet and self.iscop:
- ran = random.randint(1,3)
- if ran == 2:
- self.sheeprole = 'cop'
- elif ran == 3:
- self.sheeprole = 'det'
- elif ran == 1:
- self.sheeprole = 'oc'
- else:
- print 'sheeprole borked'
- elif self.isdoc == False and self.iscop == False and self.isdet:
- ran = random.randint(1,2)
- if ran == 2:
- self.sheeprole = 'det'
- elif ran == 1:
- self.sheeprole = 'oc'
- else:
- print 'sheeprole borked'
- elif self.isdoc == False and self.isdet == False and self.iscop:
- ran = random.randint(1,2)
- if ran == 2:
- self.sheeprole = 'cop'
- elif ran == 1:
- self.sheeprole = 'oc'
- else:
- print 'sheeprole borked'
- else:
- self.sheeprole = 'oc'
- print "MY SHEEPROLE IS: "+self.sheeprole
- def sheriffday(self, channel):
- print "sheriffday"
- isit = False
- guiltylist = []
- innocentlist = []
- if len(self.maflist) > 0:
- for night in self.maflist:
- guiltylist.append(" checked %s night %d" % (self.maflist[night], self.nightnum))
- copguiltreplist = ', '.join(copguiltreplist)
- print copguiltreplist
- copposchoice = random.choice(self.coppos)
- self.msg(channel, (copposchoice,copguiltreplist))
- if len(self.innolist) > 0:
- for user in self.innolist:
- if user in self.scumlevel.keys():
- del self.scumlevel[user]
- for night in self.innolist:
- copinnoreplist.append(" checked %s night %d" % (self.maflist[night], night))
- copinnoreplist = ', '.join(copinnoreplist)
- print copinnoreplist
- copinnochoice = random.choice(self.copinno)
- self.msg(channel, (copinnochoice, copinnoreplist))
- self.alreadyclaimed = True
- def detectiveday(self, channel):
- print "detectiveday"
- followedreport = []
- for person in self.rolelist:
- followedreport.append(" %s was a %s" % (person, self.rolelist[person]))
- followedreport = ', '.join(followedreport)
- detchoice = random.choice(self.detness)
- self.msg(channel, (detchoice, followedreport))
- def docday(self, channel):
- print "docday"
- savedreport = []
- for person in self.saveddict:
- savedreport.append(" saved %s night %d" % (person, self.rolelist[person]))
- savedreport = ', '.join(savedreport)
- docchoice = random.choice(self.docsave)
- self.msg(channel, (docchoice, savedreport))
- def lynchscummiest(self, user, channel):
- self.scumlevel[user] += 10
- topscummy = {}
- for player, scumlevel in self.scumlevel.iteritems():
- if scumlevel not in topscummy:
- topscummy[scumlevel] = []
- topscummy[scumlevel].append(player)
- if len(self.claimdict['cop']) > 1 and self.alreadylynch == False:
- choice = random.choice(self.claimdict['cop'])
- self.msg(channel, "I choose this cop claim to be mafia!")
- self.msg(channel, "!lynch "+choice)
- self.alreadylynch = True
- return
- elif len(self.claimdict['doc']) > 1 and self.alreadylynch == False:
- choice = random.choice(self.claimdict['doc'])
- self.msg(channel, "I choose this doc claim to be mafia!")
- self.msg(channel, "!lynch "+choice)
- self.alreadylynch = True
- return
- elif len(self.claimdict['det']) > 1 and self.alreadylynch == False:
- choice = random.choice(self.claimdict['det'])
- self.msg(channel, "I choose this det claim to be mafia!")
- self.msg(channel, "!lynch "+choice)
- self.alreadylynch = True
- return
- else:
- print topscummy
- sortedscummy = sorted(topscummy.iteritems(), reverse=True, key=lambda n:n[0])
- print sortedscummy[0][1][0]
- print '^ is the scummiest in my eyes'
- topscumbag = sortedscummy[0][1][0]
- if self.topscum != topscumbag:
- self.topscum = topscumbag
- explain = random.choice(self.explainlynchscum)
- self.msg(channel, explain)
- self.msg(channel, '!lynch '+self.topscum)
- self.doneaction = True
- elif self.topscum == topscumbag:
- alreadydone = random.choice(self.alreadylynched)
- self.msg(channel, alreadydone)
- else:
- alreadydone = random.choice(self.alreadylynched)
- self.msg(channel, alreadydone)
- class KomurinFactory(protocol.ClientFactory): #A 'factory' for the bot.
- protocol = Komurin
- def __init__(self, channel):
- self.channel = channel
- def clientConnectionLost(self, connector, reason): #We got disconnected, reconnect.
- connector.connect()
- def clientConnectionFailed(self, connector, reason):
- print "connection failed:", reason
- reactor.stop()
- if __name__ == '__main__': #Check if we ran it, not imported it.
- dev = '#mafia-testing'
- chan = '#mafia'
- #global debug
- if debug:
- f = KomurinFactory(dev) #No spaces between channels
- else:
- f = KomurinFactory(chan)
- reactor.connectTCP("irc.foonetic.net", 6667, f) #Connect the factory to the network.
- reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement