Esempio n. 1
0
	def OnPrivateMessage(self, user, message):
		message = message.lower()
		sender = user.nickname.lower()
		if not nickname_in_game(sender):
			return
		if message == 'help':
			send_and_notice(self._bot, sender, '/msg ' + self._bot.nickname + ' (A)pprove or (R)eject to approve or reject the mission.')
			return
		if message == 'retract':
			self.playervotes.pop(sender)
			return
		if message == 'approve' or message == 'a':
			if sender in self.playervotes:
				self.playervotes.pop(sender)
			self.playervotes[sender] = 1
		elif message == 'reject' or message == 'r':
			if sender in self.playervotes:
				self.playervotes.pop(sender)
			self.playervotes[sender] = 0
		numplayers = len(players)
		if len(self.playervotes) == numplayers:
			vote = sum(self.playervotes.values()) >= (numplayers / 2.0)
			self._bot.send_message(gamechannel, textformat.bold('Here is the vote:'))
			for player in self.playervotes.iterkeys():
				playername = get_proper_capitalized_player(player)
				votetext = 'Yes' if self.playervotes[player] else 'No'
				self._bot.send_message(gamechannel, textformat.bold(playername + ': ' + votetext))
			if vote:
				self._bot.go_to_state('Mission')
			else:
				self._bot.send_message(gamechannel, textformat.bold('The team was rejected!'))
				self._bot.go_to_state('Leading')
Esempio n. 2
0
 def on_join(self, event):
     message = '{0}: {1} [{2}]'.format(format.color(format.bold('Uploaded patch diff'), format.GREEN),
                                         format.color(format.bold(self.patch), format.DARK_GRAY),
                                         self.address + self.patch.replace(' ', '_') + '#Files_changed'
                                         )
     self.send_message(event.target, message)
     self.quit()
Esempio n. 3
0
	def OnEnterState(self):
		self._bot.send_message(gamechannel, textformat.bold('The roles were:'))
		for player in players:
			if player in spies:
				self._bot.send_message(gamechannel, textformat.bold(player + ' => Spy'))
			else:
				self._bot.send_message(gamechannel, textformat.bold(player + ' => Resistance'))
		self._bot.go_to_state('Idle')
Esempio n. 4
0
 def OnEnterState(self):
     self._bot.send_message(gamechannel, textformat.bold('The roles were:'))
     for player in players:
         if player in spies:
             self._bot.send_message(gamechannel,
                                    textformat.bold(player + ' => Spy'))
         else:
             self._bot.send_message(
                 gamechannel, textformat.bold(player + ' => Resistance'))
     self._bot.go_to_state('Idle')
Esempio n. 5
0
	def OnEnterState(self):
		self.leader = leaderlist[0]
		team[:] = []
		numplayers = len(players)
		self.teamsize = lookup_team_size(numplayers, roundnum)
		sabotagesize = lookup_sabotage_size(numplayers, roundnum)

		self._bot.send_message(gamechannel, textformat.bold(
			'Round ' + str(roundnum) + '/5. Resistance: ' + str(roundnum-1-failedmissions) + ', Spies: ' + str(failedmissions) + '. Rejected teams this round: ' + str(leaderattempts) + '. Team size: ' + str(self.teamsize) + '. Fails required: ' + str(sabotagesize) + '.'))
		self._bot.send_message(gamechannel, textformat.bold(
			'The current leader is ' + get_proper_capitalized_player(self.leader) + '. The order of leaders will be ' + collate_players(leaderlist)))
		self.send_syntax_to_leader()
Esempio n. 6
0
    def OnPrivateMessage(self, user, message):
        message = message.lower()
        global roundnum
        if user.nickname.lower() not in team:
            return
        if message == 'help':
            send_and_notice(
                self._bot, user.nickname,
                '/message (S)uccess or (F)ailure to succeed or fail the mission.'
            )
            return
        if message == 'retract':
            self.playervotes.pop(user.nickname.lower())
        if message == 'success' or message == 's':
            self.playervotes[user.nickname.lower()] = 0
        elif message == 'failure' or message == 'f':
            if user.nickname.lower() not in spies:
                self._bot.send_message(
                    user.nickname,
                    'Loyal Resistance members should always vote SUCCESS, please vote again.'
                )
                return
            self.playervotes[user.nickname.lower()] = 1
        if len(self.playervotes) == len(team):
            numfails = sum(self.playervotes.values())
            vote = numfails >= lookup_sabotage_size(len(players), roundnum)
            if vote:
                global failedmissions
                failedmissions += 1
            resulttext = 'failure' if vote else 'success'
            votetext = ' vote' if numfails == 1 else ' votes'

            self._bot.send_message(
                gamechannel,
                textformat.bold('There were ' + str(numfails) + votetext +
                                ' to sabotage. The mission was a ' +
                                resulttext + '!'))
            if failedmissions == 3:
                self._bot.send_message(
                    gamechannel,
                    textformat.bold('The game is over. Spies win!'))
                self._bot.go_to_state('Endgame')
            elif (roundnum - failedmissions) == 3:
                self._bot.send_message(
                    gamechannel,
                    textformat.bold('The game is over, The Resistance wins!'))
                self._bot.go_to_state('Endgame')
            else:
                roundnum += 1
                time.sleep(random.randint(2, 6))

                self._bot.go_to_state('Leading')
Esempio n. 7
0
def cmd_help( self, command, params, event, received="channel" ):
        """ {0}!X!- Help for commands
                {0}!X!- List commands
                {0} <COMMAND>!X!- Help for <COMMAND>"""

        if len( params ) < 1:
                self.send_message( event.source, "List of commands:" )
                for cmd in self.commands:
                        self.send_message( event.source, format.color( "## ", format.LIME_GREEN ) + '{:<20} {}'.format( *self.commands[ cmd ][1].__doc__.format( format.bold( format_command( cmd, received ) ) ).splitlines()[0].strip().split( "!X!", 1 ) ) ) # split and justify
                return
        if params[0].lower() in self.commands:
                self.send_message( event.source, "Usage info for command {0}:".format( format.bold( params[0] ) ) )
                for line in self.commands[ params[0].lower() ][1].__doc__.format( *[ format.bold( format_command( c, received ) ) for c in params ] ).splitlines():
                        self.send_message( event.source, format.color( "## ", format.LIME_GREEN ) + '{:<35} {}'.format( *line.strip().split( "!X!", 1 ) ) ) # split and justify
        else:
                self.send_message( event.source, "Unkown Command {0}.".format( format.bold( params[0] ) ) )
Esempio n. 8
0
def replace_user(olduser, newuser, bot):
	# This is a little ugly; we can't replace the underlying user object with the right info
	# Since there's no way to get hostmask on demand
	if not nickname_in_game(olduser.nickname) or nickname_in_game(newuser.nickname):
		return
	bot.devoice_nick(olduser.nickname, gamechannel)

	bot.send_message(gamechannel, textformat.bold('Replacing ' + olduser.nickname + ' with ' + newuser.nickname + '.'))
	players.pop(olduser.nickname.lower())
	players[newuser.nickname.lower()] = newuser

	if olduser.nickname in leaderlist:
		leaderlist[leaderlist.index(olduser.nickname)] = newuser.nickname.lower()

	if olduser.nickname in team:
		team[team.index(olduser.nickname)] = newuser.nickname.lower()

	if olduser.nickname in spies:
		spies[spies.index(olduser.nickname)] = newuser.nickname.lower()
		send_and_notice(bot, newuser.nickname, 'You are an IMPERIAL SPY! The spies are ' + collate_players(spies))
	elif bot.state.name != 'Forming':
		send_and_notice(bot, newuser.nickname, 'You are a loyal member of The Resistance.')

	if voiced:
		bot.voice_nick(newuser.nickname, gamechannel)
Esempio n. 9
0
def respond(bot, event):
    matches = []
    for (ident, (regex, template)) in bot.commands_cache.iteritems():
        match = regex.search(event.message)
        if match:
            params = match.groupdict()
            params['nick'] = event.source
            heappush(
                matches, (match.start(0), template.safe_substitute(params))
            )

    if not matches:
        if event.message.find("http") != -1:
            br = Browser()
            try:
                br.set_handle_robots(False)
                br.open(event.message)
                bot.send_channel_action(bot.config.messages.urltitle, title = format.bold('\"' + br.title() + '\"'))
            except:
                return False
            return True
        else:
            return False

    bot.send_channel_action(matches[0][1])
    return True
Esempio n. 10
0
def cmd_banner( self, command, params, event, received="channel" ):
        """{0}!X!- Print an ASCII Banner
                {0} <BANNER>!X!- Print <BANNER>
                {0} <BANNER> <CHANNEL>!X!- Print <BANNER> in <CHANNEL>"""

        rec = event.target
        if received == "private":
                rec = event.source
        if len( params ) > 1:
                rec = params[1]

        banner = None
        if params[0] == "text":
                banner = (format.BLUE, requests.get( "https://artii.herokuapp.com/make", params={"text": " ".join(params[2:])}).text.splitlines())
        elif params[0] == "graffiti":
                banner = (format.BLUE, requests.get( "https://artii.herokuapp.com/make", params={"text": " ".join(params[2:]), "font": "graffiti"}).text.splitlines() )
        elif params[0] in banners:
                banner = banners[params[0]]
        else:
                self.send_message( rec, format.color( "ERROR:", format.RED ) + " Banner not found" )
                return

        for line in banner[1]:
                self.send_message( rec, format.color( format.bold( line ), banner[0], format.BLACK ) )
                time.sleep( 0.5 )
Esempio n. 11
0
def cmd_exec( self, command, params, event, received="channel" ):
        """ {0}!X!- Execute an IRC command
                {0} <COMMAND> <[PARAMS]>!X!- Execute the IRC command <COMMAND> with parameters <PARAMS>"""

        self.execute( params[0].upper(), ' '.join( params[1:] ).strip() )
        if received == "private":
                self.send_message( event.source, "Executed" + format.bold( params[0].upper() + ' '.join( params[1:] ) ) )
Esempio n. 12
0
def replace_user(olduser, newuser, bot):
    # This is a little ugly; we can't replace the underlying user object with the right info
    # Since there's no way to get hostmask on demand
    if not nickname_in_game(olduser.nickname) or nickname_in_game(
            newuser.nickname):
        return
    bot.devoice_nick(olduser.nickname, gamechannel)

    bot.send_message(
        gamechannel,
        textformat.bold('Replacing ' + olduser.nickname + ' with ' +
                        newuser.nickname + '.'))
    players.pop(olduser.nickname.lower())
    players[newuser.nickname.lower()] = newuser

    if olduser.nickname in leaderlist:
        leaderlist[leaderlist.index(
            olduser.nickname)] = newuser.nickname.lower()

    if olduser.nickname in team:
        team[team.index(olduser.nickname)] = newuser.nickname.lower()

    if olduser.nickname in spies:
        spies[spies.index(olduser.nickname)] = newuser.nickname.lower()
        send_and_notice(
            bot, newuser.nickname,
            'You are an IMPERIAL SPY! The spies are ' + collate_players(spies))
    elif bot.state.name != 'Forming':
        send_and_notice(bot, newuser.nickname,
                        'You are a loyal member of The Resistance.')

    if voiced:
        bot.voice_nick(newuser.nickname, gamechannel)
Esempio n. 13
0
    def on_join( self, event ):
        if event.source != self.nickname: # don't welcome yourself
            self.send_message( event.target, "Welcome to " + format.color( format.bold( ' LTFU :' ), format.BLACK, format.LIGHT_GRAY ) + format.color( ': hangout ', format.WHITE, format.GREEN ) + ", " +  format.bold( event.source ) )

        if event.source in self.tell and self.tell[event.source] != False:
            for m in self.tell[event.source]:
                self.send_message( m[1], "[{}] {}".format(time.strftime("%H:%M", (m[0])), m[2]) )

        self.tell[event.source] = False # False = online but known
Esempio n. 14
0
	def OnEnterState(self):
		global leaderattempts
		leaderattempts = 0

		self.playervotes = dict()
		sabotagesize = lookup_sabotage_size(len(players), roundnum)
		votetext = 'vote is' if sabotagesize == 1 else 'votes are'
		self._bot.send_message(gamechannel, textformat.bold(
			'The team was accepted! Team is ' + collate_players(team) + '. ' + str(sabotagesize) + ' ' + votetext + ' required to fail this mission.'))
		for player in team:
			send_and_notice(self._bot, player, '/message (S)uccess or (F)ailure to succeed or fail the mission.')
Esempio n. 15
0
	def OnEnterState(self):
		self.leader = leaderlist[0]
		leaderlist.append(leaderlist.pop(0))
		self._bot.send_message(gamechannel, textformat.bold(
			get_proper_capitalized_player(self.leader) + ' picked this team: ' + collate_players(team) + '. This is attempt ' + str(leaderattempts) + '. The mission is automatically accepted after 5 attempts.'))
		if leaderattempts == 5:
			self._bot.go_to_state('Mission')
			return
		for player in players.iterkeys():
			send_and_notice(self._bot, player, 
				'/msg ' + self._bot.nickname + ' either (A)pprove or (R)eject to indicate your support or rejection of this mission. Majority rules, ties ruled in favor of the mission.')
		self.playervotes = dict()
Esempio n. 16
0
	def OnEnterState(self):
		global voiced
		voiced = True 

		global leaderattempts
		leaderattempts = 0

		global failedmissions
		failedmissions = 0

		players.clear()
		send_and_notice(self._bot, gamechannel, textformat.bold('New game forming, type !join to join.'))
Esempio n. 17
0
	def OnPrivateMessage(self, user, message):
		message = message.lower()
		global roundnum
		if user.nickname.lower() not in team:
			return
		if message == 'help':
			send_and_notice(self._bot, user.nickname, '/message (S)uccess or (F)ailure to succeed or fail the mission.')
			return
		if message == 'retract':
			self.playervotes.pop(user.nickname.lower())
		if message == 'success' or message == 's':
			self.playervotes[user.nickname.lower()] = 0
		elif message == 'failure' or message == 'f':
			if user.nickname.lower() not in spies:
				self._bot.send_message(user.nickname, 'Loyal Resistance members should always vote SUCCESS, please vote again.')
				return
			self.playervotes[user.nickname.lower()] = 1
		if len(self.playervotes) == len(team):
			numfails = sum(self.playervotes.values())
			vote = numfails >= lookup_sabotage_size(len(players), roundnum)
			if vote:
				global failedmissions
				failedmissions += 1	
			resulttext = 'failure' if vote else 'success'
			votetext = ' vote' if numfails == 1 else ' votes'

			self._bot.send_message(gamechannel, textformat.bold('There were ' + str(numfails) + votetext + ' to sabotage. The mission was a ' + resulttext + '!'))
			if failedmissions == 3:
				self._bot.send_message(gamechannel, textformat.bold('The game is over. Spies win!'))
				self._bot.go_to_state('Endgame')
			elif (roundnum - failedmissions) == 3:
				self._bot.send_message(gamechannel, textformat.bold('The game is over, The Resistance wins!'))
				self._bot.go_to_state('Endgame')
			else:
				roundnum += 1
				time.sleep(random.randint(2, 6))

				self._bot.go_to_state('Leading')
Esempio n. 18
0
    def OnEnterState(self):
        global voiced
        voiced = True

        global leaderattempts
        leaderattempts = 0

        global failedmissions
        failedmissions = 0

        players.clear()
        send_and_notice(
            self._bot, gamechannel,
            textformat.bold('New game forming, type !join to join.'))
Esempio n. 19
0
    def OnEnterState(self):
        self.leader = leaderlist[0]
        team[:] = []
        numplayers = len(players)
        self.teamsize = lookup_team_size(numplayers, roundnum)
        sabotagesize = lookup_sabotage_size(numplayers, roundnum)

        self._bot.send_message(
            gamechannel,
            textformat.bold('Round ' + str(roundnum) + '/5. Resistance: ' +
                            str(roundnum - 1 - failedmissions) + ', Spies: ' +
                            str(failedmissions) +
                            '. Rejected teams this round: ' +
                            str(leaderattempts) + '. Team size: ' +
                            str(self.teamsize) + '. Fails required: ' +
                            str(sabotagesize) + '.'))
        self._bot.send_message(
            gamechannel,
            textformat.bold('The current leader is ' +
                            get_proper_capitalized_player(self.leader) +
                            '. The order of leaders will be ' +
                            collate_players(leaderlist)))
        self.send_syntax_to_leader()
Esempio n. 20
0
 def announce(self, submission, channel):
     msg = self.MSG_FORMAT.format(
         url=submission.url,
         permalink=submission.permalink,
         shortlink=format.color(submission.short_link[7:], format.RED),
         subreddit=format.color(text_type(submission.subreddit), format.GREEN),
         author=format.color(text_type(submission.author), format.GREEN),
         title=submission.title,
     ).encode("utf-8")
     msg = format.color(re.sub("\s+", " ", msg).strip(), format.GREEN)
     if debug:
         print(msg)
     msg = format.bold(msg)
     self.send_action(channel, msg)
Esempio n. 21
0
 def OnPrivateMessage(self, user, message):
     message = message.lower()
     sender = user.nickname.lower()
     if not nickname_in_game(sender):
         return
     if message == 'help':
         send_and_notice(
             self._bot, sender, '/msg ' + self._bot.nickname +
             ' (A)pprove or (R)eject to approve or reject the mission.')
         return
     if message == 'retract':
         self.playervotes.pop(sender)
         return
     if message == 'approve' or message == 'a':
         if sender in self.playervotes:
             self.playervotes.pop(sender)
         self.playervotes[sender] = 1
     elif message == 'reject' or message == 'r':
         if sender in self.playervotes:
             self.playervotes.pop(sender)
         self.playervotes[sender] = 0
     numplayers = len(players)
     if len(self.playervotes) == numplayers:
         vote = sum(self.playervotes.values()) >= (numplayers / 2.0)
         self._bot.send_message(gamechannel,
                                textformat.bold('Here is the vote:'))
         for player in self.playervotes.iterkeys():
             playername = get_proper_capitalized_player(player)
             votetext = 'Yes' if self.playervotes[player] else 'No'
             self._bot.send_message(
                 gamechannel, textformat.bold(playername + ': ' + votetext))
         if vote:
             self._bot.go_to_state('Mission')
         else:
             self._bot.send_message(
                 gamechannel, textformat.bold('The team was rejected!'))
             self._bot.go_to_state('Leading')
Esempio n. 22
0
	def OnChannelMessage(self, user, channel, message):
		message = message.lower()
		playing = nickname_in_game(user.nickname)
		if message == '!cancel':
			self._bot.send_message(gamechannel, textformat.bold('Game cancelled.'))
			self._bot.go_to_state('Idle')
			return
		elif message == '!join':
			if not playing:
				players[user.nickname.lower()] = user
				self._bot.voice_nick(user.nickname, gamechannel)
			return
		elif message == "!leave":
			if playing:
				players.pop(user.nickname.lower())
				self._bot.devoice_nick(user.nickname, gamechannel)
				if len(players) == 0:
					self._bot.send_message(gamechannel, textformat.bold('Game cancelled.'))
					self._bot.go_to_state('Idle')
			return
		elif message == '!formed':
			if len(players) < minplayers or len(players) > maxplayers:
				playertext = 'is 1 player' if len(players) == 1 else 'are ' + str(len(players)) + ' players'
				self._bot.send_message(gamechannel,
					textformat.bold('There ' + playertext + ' in the game. Need between ' + str(minplayers) + ' and ' + str(maxplayers) + ' to start.'))
				return
			else:
				global roundnum
				roundnum = 1

				self._bot.moderate_channel(gamechannel)
				numplayers = len(players)
				numspies = lookup_num_spies(numplayers)
				self._bot.send_message(gamechannel, textformat.bold('Game formed with ' + str(numspies) + ' spies and ' + str(numplayers - numspies) + ' + Resistance members.'))

				leaderlist[:] = []
				for player in players.iterkeys():
					leaderlist.append(player)

				random.shuffle(leaderlist)
				spies[:] = leaderlist[:numspies]
				for player in spies:
					send_and_notice(self._bot, player, 'You are an IMPERIAL SPY! The spies are ' + collate_players(spies))
				for player in leaderlist[numspies:]:
					send_and_notice(self._bot, player, 'You are a loyal member of The Resistance.')
				random.shuffle(leaderlist)

				text = "Team size by round: " + ', '.join(get_team_grid(numplayers))
				self._bot.send_message(gamechannel, textformat.bold(text))

				text = "Number of fails needed by round: " + ', '.join(get_sabotage_grid(numplayers))
				self._bot.send_message(gamechannel, textformat.bold(text))

				self._bot.go_to_state('Leading')
Esempio n. 23
0
    def OnEnterState(self):
        global leaderattempts
        leaderattempts = 0

        self.playervotes = dict()
        sabotagesize = lookup_sabotage_size(len(players), roundnum)
        votetext = 'vote is' if sabotagesize == 1 else 'votes are'
        self._bot.send_message(
            gamechannel,
            textformat.bold('The team was accepted! Team is ' +
                            collate_players(team) + '. ' + str(sabotagesize) +
                            ' ' + votetext +
                            ' required to fail this mission.'))
        for player in team:
            send_and_notice(
                self._bot, player,
                '/message (S)uccess or (F)ailure to succeed or fail the mission.'
            )
Esempio n. 24
0
 def OnEnterState(self):
     self.leader = leaderlist[0]
     leaderlist.append(leaderlist.pop(0))
     self._bot.send_message(
         gamechannel,
         textformat.bold(
             get_proper_capitalized_player(self.leader) +
             ' picked this team: ' + collate_players(team) +
             '. This is attempt ' + str(leaderattempts) +
             '. The mission is automatically accepted after 5 attempts.'))
     if leaderattempts == 5:
         self._bot.go_to_state('Mission')
         return
     for player in players.iterkeys():
         send_and_notice(
             self._bot, player, '/msg ' + self._bot.nickname +
             ' either (A)pprove or (R)eject to indicate your support or rejection of this mission. Majority rules, ties ruled in favor of the mission.'
         )
     self.playervotes = dict()
Esempio n. 25
0
        def on_private_message( self, event ):
                message = event.message.split()
                command = message[0].upper()
                params  = message[1:]

                if command.lower() in self.commands:
                        ( level, func ) = self.commands[ command.lower() ]

                        for name in self.channelusers[next(iter(self.channels))]: # FIXME: random channel
                                if protocol.strip_name_symbol( name ) == event.source: break # name is now event.target's name

                        ulevel = 0
                        if name[0] in self.access: # do not handle 'empty' users
                                ulevel = self.access[ name[0] ]

                        if ulevel < self.access[ level ]:
                                self.send_message( event.source, format.color( "ERROR:", format.RED ) + " You are not allowed to use the " + format.bold( command ) + " Command" )
                                return
                        func( self, command, params, event, received="private" ) # tell the function this was a private message and call it
Esempio n. 26
0
        def on_channel_message( self, event ):
                message = event.message.split()
                command = message[0]
                params  = message[1:]

                if len( command ) == 1: # skip single !'s and stuff
                        return

                if command[0] == "!": # only handle commands directed to us...
                        command =  command[1:].lower()
                        if command in self.commands: # ... that exist
                                ( level, func ) = self.commands[ command ]

                                for name in self.channelusers[ event.target ]:
                                        if protocol.strip_name_symbol( name ) == event.source: break # name is now event.target's name

                                ulevel = 0
                                if name[0] in self.access: # do not handle 'empty' users
                                        ulevel = self.access[ name[0] ]

                                if  ulevel < self.access[ level ]:
                                        self.send_message( event.target, format.color( "ERROR:", format.RED ) + " You are not allowed to use the " + format.bold( command ) + " Command" )
                                        return
                                func( self, command, params, event )
Esempio n. 27
0
 def on_join( self, event ):
         if event.source != self.nickname: # don't welcome yourself
                 self.send_message( event.target, "Welcome to " + format.color( format.bold( ' LTFU :' ), format.BLACK, format.LIGHT_GRAY ) + format.color( ': hangout ', format.WHITE, format.GREEN ) + ", " +  format.bold( event.source ) )
Esempio n. 28
0
    def OnChannelMessage(self, user, channel, message):
        message = message.lower()
        playing = nickname_in_game(user.nickname)
        if message == '!cancel':
            self._bot.send_message(gamechannel,
                                   textformat.bold('Game cancelled.'))
            self._bot.go_to_state('Idle')
            return
        elif message == '!join':
            if not playing:
                players[user.nickname.lower()] = user
                self._bot.voice_nick(user.nickname, gamechannel)
            return
        elif message == "!leave":
            if playing:
                players.pop(user.nickname.lower())
                self._bot.devoice_nick(user.nickname, gamechannel)
                if len(players) == 0:
                    self._bot.send_message(gamechannel,
                                           textformat.bold('Game cancelled.'))
                    self._bot.go_to_state('Idle')
            return
        elif message == '!formed':
            if len(players) < minplayers or len(players) > maxplayers:
                playertext = 'is 1 player' if len(
                    players) == 1 else 'are ' + str(len(players)) + ' players'
                self._bot.send_message(
                    gamechannel,
                    textformat.bold('There ' + playertext +
                                    ' in the game. Need between ' +
                                    str(minplayers) + ' and ' +
                                    str(maxplayers) + ' to start.'))
                return
            else:
                global roundnum
                roundnum = 1

                self._bot.moderate_channel(gamechannel)
                numplayers = len(players)
                numspies = lookup_num_spies(numplayers)
                self._bot.send_message(
                    gamechannel,
                    textformat.bold('Game formed with ' + str(numspies) +
                                    ' spies and ' +
                                    str(numplayers - numspies) +
                                    ' + Resistance members.'))

                leaderlist[:] = []
                for player in players.iterkeys():
                    leaderlist.append(player)

                random.shuffle(leaderlist)
                spies[:] = leaderlist[:numspies]
                for player in spies:
                    send_and_notice(
                        self._bot, player,
                        'You are an IMPERIAL SPY! The spies are ' +
                        collate_players(spies))
                for player in leaderlist[numspies:]:
                    send_and_notice(
                        self._bot, player,
                        'You are a loyal member of The Resistance.')
                random.shuffle(leaderlist)

                text = "Team size by round: " + ', '.join(
                    get_team_grid(numplayers))
                self._bot.send_message(gamechannel, textformat.bold(text))

                text = "Number of fails needed by round: " + ', '.join(
                    get_sabotage_grid(numplayers))
                self._bot.send_message(gamechannel, textformat.bold(text))

                self._bot.go_to_state('Leading')
Esempio n. 29
0
 def OnLeaveState(self):
     self._bot.send_message_all_channels(
         textformat.bold(
             'Turning back on. Type !newgame to start a new game.'))
Esempio n. 30
0
	def OnLeaveState(self):
		self._bot.send_message_all_channels(textformat.bold('Turning back on. Type !newgame to start a new game.'))
Esempio n. 31
0
	def OnEnterState(self):
		self._bot.send_message_all_channels(textformat.bold('Turning off. Cancelling any game in progress.'))
Esempio n. 32
0
 def OnEnterState(self):
     self._bot.send_message_all_channels(
         textformat.bold('Turning off. Cancelling any game in progress.'))
Esempio n. 33
0
def announce_arrival(bot, event):
    if not (event.source == bot.nickname):
        return False

    bot.send_channel_action(format.bold(bot.config.messages.announce_arrival))
    return True
Esempio n. 34
0
    def on_channel_message( self, event ):
        message = event.message.split()
        command = message[0]
        params  = message[1:]
        self.currentNick = event.source

        if event.source not in self.tell:
            self.tell[event.source] = False

        if command[0] == "!": # only handle commands directed to us...
            if len( command ) == 1: # skip single !'s and stuff
                return

            command =  command[1:].lower()
            if command in self.commands: # ... that exist
                ( level, func ) = self.commands[ command ]

                for name in self.channelusers[ event.target ]:
                    if protocol.strip_name_symbol( name ) == event.source: break # name is now event.target's name

                ulevel = 0
                if name[0] in self.access: # do not handle 'empty' users
                    ulevel = self.access[ name[0] ]

                if  ulevel < self.access[ level ]:
                    self.send_message( event.target, format.color( "ERROR:", format.RED ) + " You are not allowed to use the " + format.bold( command ) + " Command" )
                    return
                func( self, command, params, event )
        elif self.tellre.match(event.message):
            nick = self.tellre.match(event.message).groups()[0]

            if nick in self.tell and self.tell[nick] != False: # known but nont online
                self.tell[nick].append((time.gmtime(), event.target, "{}: {}".format(event.source, format.color(event.message, format.GREEN))))
                self.send_message(event.target, "I'll pass that on to {}".format(nick))
Esempio n. 35
0
	def OnChannelMessage(self, user, channel, message):
		if is_owner(user) and message.lower() == '!nullgame' and self._bot.state.name != 'Off':
			self._bot.send_message(gamechannel, textformat.bold('Game nulled.'))
			self._bot.go_to_state('Idle')
Esempio n. 36
0
 def OnChannelMessage(self, user, channel, message):
     if is_owner(user) and message.lower(
     ) == '!nullgame' and self._bot.state.name != 'Off':
         self._bot.send_message(gamechannel,
                                textformat.bold('Game nulled.'))
         self._bot.go_to_state('Idle')