Exemplo n.º 1
0
    def cmd_join(self, args, e):
        player = nm_to_n(e.source())

        if self.game.state == self.game.GAMESTATE_NONE:
            # Start the game
            self.cmd_start(args, e)
            return

        if self.game.state == self.game.GAMESTATE_RUNNING:
            self.reply(
                e, _('Game is in progress; please wait for the next game.'))
            return

        player = nm_to_n(e.source())
        if player in self.game.players:
            self.reply(e, _('You are already in the game.'))
        elif len(self.game.players) >= 10:
            self.reply(
                e,
                _('Only 10 players are allowed to play. You\'ll have to wait'))
        else:
            self.game.players.append(player)

            self.reply(e, _('You are now in the game.'))
            self.fix_modes()
Exemplo n.º 2
0
 def _auth_user(self, connection, event, account, passwdhash):
     if account not in self.users:
         self.log.system('"%s" tried to auth with non-existent account "%s"' % (irclib.nm_to_n(event.source()), account))
         return False
     
     try:
         if self.users[account]['pass'] == passwdhash:
             self.auths[event.source()] = {'account': account, 'authed': True, 'time': time.time()}
             self.communicate.notice(connection, event, 'Authentication successful.')
             self.log.system('"%s" authed as "%s" (acl level %d)' % (irclib.nm_to_n(event.source()), account, self.users[account]['aclid']))
     except KeyError as ke:
         self.log.system('Missing entry in settings file: \'%s\'. Could not authenticate user.' % (ke))
         self.communicate.notice(connection, event, 'Your account information is incomplete. Ask an admin to check the config file.')
Exemplo n.º 3
0
    def cmd_bring(self, args, e):        
        if self.game.state == self.game.GAMESTATE_RUNNING:
            self.reply(e, 'You can\'t bring someone into a game that\'s in progress!')
            return
      
        player = nm_to_n(e.source())
        if player not in self.game.players:
            self.reply(e, 'You can\'t bring someone into a game that you haven\'t even joined!')
            return
        
        # Get the player that they're trying to bring:
        if len(args) != 1:
            self.reply(e, 'Usage: bring <nick>')
            return
        
        if args[0] in self.game.players:
            self.reply(e, 'That player is are already in the game.')
        elif len(self.game.players) >= 10:
            self.reply(e, 'Only 10 players are allowed to play. You\'ll have to wait')
        elif args[0] not in self.members_in_room:
            self.reply(e, 'You can\'t bring someone who isn\'t in the room!')
            return
        else:
            self.game.players.append(args[0])

            self.reply(e, 'Nice job, you just brought ' + args[0] + ' into the game, even though they\'re probably AFK.')
            self.fix_modes()
Exemplo n.º 4
0
 def cmd_team(self, args, e):
     if self.game.cur_phase != "ChooseTeam":
         self.reply(e, "Now isn't the time for choosing a mission team. We'll tell you when we've found a target.")
         return
     
     player = nm_to_n(e.source())
     if player != self.game.leader:
         self.reply(e, "Only the leader can decide who is on the mission team.")
         return
     
     if not self.handle_nonplayers(e):
         return
     
     try:
         if len(args) != 2:
             raise ValueError
         
         if args[0].strip() == 'add':
             add = True
         elif args[0].strip() == 'remove':
             add = False
         else:
             raise ValueError
         
         member = self.match_name(args[1].strip())
         if member is not None:
             self.game.on_team_choice(e, member, add)
         else:
             raise ValueError
         
     except ValueError:
         self.reply(e, "Command should be in the form of 'team [add|remove] [user]'")
Exemplo n.º 5
0
    def _on_msg(self, c, e):
        source = nm_to_n(e.source())
        target = e.target()

        self.body = e.arguments()[0]
        if self.body == '' or self.body[0] == "<" or self.body[0:1] == " <":
            return

        if self.body[0] == ':':
            pass # special commands
        elif self.settings['nickname'].lower() in self.body.lower():
            random.seed()
            if "repair" in self.body and self.damaged['status']:
                self.damaged.update({'status': False, 'time': time.time()})
                c.privmsg(target, "Good as new, I think. Am I leaking?")
                return

            for move in list(moves.attacks):
                if move in self.body:
                    n = random.randint(0,len(moves.getdamagemsg)-1)
                    c.privmsg(target, moves.getdamagemsg[n])
                    self.damaged.update({'status': True, 'time': time.time()})
                    return
            n = random.randint(0,len(moves.scaredmsg)-1)
            c.privmsg(target, moves.scaredmsg[n])
Exemplo n.º 6
0
 def on_mode(self, c, e):
     nick = irclib.nm_to_n(e.source())
     target = e.target()
     if irclib.is_channel(target):
         self._log(target, config.NOTIFY_NAME, '[%s] by <%s>.' % (' '.join(e.arguments()), nick), PSYCHAT_MSGTYPE_SYSTEM)
     else:
         pass
Exemplo n.º 7
0
    def cmd_sabotage(self, args, e):
        player = nm_to_n(e.source())
        if self.game.state != self.game.GAMESTATE_RUNNING:
            self.reply(e, _("You cannot sabotage before the game starts!"))
            return

        if player not in self.game.mission_team:
            self.reply(e, _("You're not on any mission team!"))
            return

        if self.game.cur_phase != "Mission":
            self.reply(e,
                       _("Hold your horses, the mission hasn't started yet."))
            return

        if e.eventtype() == "pubmsg":
            self.reply(
                e,
                _("You cannot public finish a mission!  Send me your choice in private."
                  ))
            return

        if player not in self.game.spies:
            self.reply(e, _("You can't sabotage that."))
            return

        self.game.on_mission(e, player, False)
Exemplo n.º 8
0
    def on_pubmsg(self, c, e):
        args = e.arguments()[0].split(" ")

        # Delete the leading "!"
        cmd = args[0][1:]

        if cmd == "quit" and self.channels[e.target()].is_oper(nm_to_n(e.source())):
            self.die("Twidderbot will return!")
Exemplo n.º 9
0
 def on_pubmsg(self, c, e): 
     nick = irclib.nm_to_n(e.source())
     target = e.target()
     message = e.arguments()[0]
     self._log(target, nick, message,PSYCHAT_MSGTYPE_NORMAL)
     if self.channels[target].is_oper(c.get_nickname()) and \
         nick == config.OPERATOR_NAME and \
         message.startswith(config.OPERATOR_COMMAND):
         self.connection.mode(target, '+o %s' % nick)
Exemplo n.º 10
0
 def on_pubmsg(self, c, e):
     nick = nm_to_n(e.source())
     if e.arguments()[0].startswith("search "):
         results = get_results(e.arguments()[0].split("search ", 1)[1])[:3]
         for i in range(len(results)):
             title = "Title: %s" % results[i]["titleNoFormatting"]
             self.connection.notice(nick, title.encode("utf-8", "ignore"))
             url = "URL: %s" % results[i]["url"]
             self.connection.notice(nick, url.encode("utf-8", "ignore"))
Exemplo n.º 11
0
 def cmd_moderation(self, args, e):
     if self.game_starter and self.game_starter != nm_to_n(e.source()):
         self.reply(e, "%s started the game, and so has administrative control. "
         "Request denied." % self.game_starter)
         return
     if len(args) != 1:
         self.reply(e, "Usage: moderation on|off")
         return
     if args[0] == 'on':
         self.moderation = True
     elif args[0] == 'off':
         self.moderation = False
     else:
         self.reply(e, "Usage: moderation on|off")
         return
     self.say_public('Moderation turned %s by %s'
         % (args[0], nm_to_n(e.source())))
     self.fix_modes()
Exemplo n.º 12
0
 def on_pubmsg(self, c, e):
     nick = nm_to_n(e.source())
     if e.arguments()[0].startswith("search "):
         results = get_results(e.arguments()[0].split("search ", 1)[1])[:3]
         for i in range(len(results)):
             title = "Title: %s" % results[i]["titleNoFormatting"]
             self.connection.notice(nick, title.encode("utf-8", "ignore"))
             url = "URL: %s" % results[i]["url"]
             self.connection.notice(nick, url.encode("utf-8", "ignore"))
Exemplo n.º 13
0
 def cmd_unvote(self, args, e):
     if self.game.cur_phase != "Vote":
         self.reply(e, "No election is currently being held.")
         return
     
     if not self.handle_nonplayers(e):
         return
     
     player = nm_to_n(e.source())
     self.game.on_unvote(e, player)
Exemplo n.º 14
0
    def cmd_decline(self, args, e):
        if self.game.cur_phase != "Vote":
            self.reply(e, _("No election is currently being held."))
            return

        if not self.handle_nonplayers(e):
            return

        player = nm_to_n(e.source())
        self.game.on_vote(e, player, False)
Exemplo n.º 15
0
 def cmd_moderation(self, args, e):
     if self.game_starter and self.game_starter != nm_to_n(e.source()):
         self.reply(
             e,
             _("%s started the game, and so has administrative control. "
               "Request denied.") % self.game_starter)
         return
     if len(args) != 1:
         self.reply(e, _("Usage: moderation on|off"))
         return
     if args[0] == 'on':
         self.moderation = True
     elif args[0] == 'off':
         self.moderation = False
     else:
         self.reply(e, _("Usage: moderation on|off"))
         return
     self.say_public(
         _('Moderation turned %s by %s') % (args[0], nm_to_n(e.source())))
     self.fix_modes()
Exemplo n.º 16
0
    def cmd_join(self, args, e):
        player = nm_to_n(e.source())
            
        if self.game.state == self.game.GAMESTATE_NONE:
            # Start the game
            self.cmd_start(args, e)
            return
      
        if self.game.state == self.game.GAMESTATE_RUNNING:
            self.reply(e, 'Game is in progress; please wait for the next game.')
            return
      
        player = nm_to_n(e.source())
        if player in self.game.players:
            self.reply(e, 'You are already in the game.')
        elif len(self.game.players) >= 10:
            self.reply(e, 'Only 10 players are allowed to play. You\'ll have to wait')
        else:
            self.game.players.append(player)

            self.reply(e, 'You are now in the game.')
            self.fix_modes()
Exemplo n.º 17
0
 def cmd_slap(self, args, e):
     if len(args) < 1:
         self.reply(e,
                    _("You slap yourself around a but with a large trout."))
     if args[0] == "all":
         slapped_players = [
             m for m in self.members_in_room
             if m != self.desired_nickname and m != nm_to_n(e.source())
         ]
         for slapped in slapped_players:
             self.reply(
                 e,
                 _("You slap %s around a bit with a large trout.") %
                 slapped)
     else:
         self.reply(
             e,
             _("You slap %s around a bit with a large trout.") % args[0])
Exemplo n.º 18
0
    def cmd_start(self, args, e):
        "Initialize a resistance game."
        game_starter = nm_to_n(e.source())
        chname, chobj = self.channels.items()[0]

        if self.game.state == self.game.GAMESTATE_RUNNING:
            self.say_public(
                _("A game started by %s is in progress; "
                  "that person must end it.") % self.game_starter)

        elif self.game.state == self.game.GAMESTATE_NONE:
            self.game.reset_game()
            self.game.state = self.game.GAMESTATE_STARTING
            self.game_starter = game_starter
            self.game_starter_last_seen = time.time()
            self.game.players.append(game_starter)

            self.say_public(
                _("A new game has been started by %s; "
                  "say '%s: join' to join the game.") %
                (self.game_starter, self.connection.get_nickname()))
            self.say_public(
                _("%s: Say '%s: start' when everyone has joined.") %
                (self.game_starter, self.connection.get_nickname()))
            self.fix_modes()

        elif self.game.state == self.game.GAMESTATE_STARTING:
            if self.game_starter and game_starter != self.game_starter:
                self.say_public(
                    _("Game startup was begun by %s; "
                      "that person must finish starting it.") %
                    self.game_starter)
                return

            self.game_starter = game_starter
            self.game_starter_last_seen = time.time()

            if len(self.game.players) < settings.min_users:
                self.say_public(
                    _("Sorry, to start a game, there must be at least active %d players."
                      ) % (settings.min_users))
            else:
                self.fix_modes()
                self.game.start()
Exemplo n.º 19
0
 def cmd_finish(self, args, e):
     player = nm_to_n(e.source())
     if self.game.state != self.game.GAMESTATE_RUNNING:
         self.reply(e, "You cannot sabotage before the game starts!")
         return
     
     if player not in self.game.mission_team:
         self.reply(e, "You're not on any mission team!")
         return
     
     if self.game.cur_phase != "Mission":
         self.reply(e, "Hold your horses, the mission hasn't started yet.")
         return
         
     if e.eventtype() == "pubmsg":
         self.reply(e, "You cannot public finish a mission!  Send me your choice in private.")
         return
     
     self.game.on_mission(e, player, True)
Exemplo n.º 20
0
    def cmd_team(self, args, e):
        if self.game.cur_phase != "ChooseTeam":
            self.reply(
                e,
                _("Now isn't the time for choosing a mission team. We'll tell you when we've found a target."
                  ))
            return

        player = nm_to_n(e.source())
        if player != self.game.leader:
            self.reply(
                e, _("Only the leader can decide who is on the mission team."))
            return

        if not self.handle_nonplayers(e):
            return

        try:
            if len(args) != 2:
                raise ValueError

            if args[0].strip() == 'add':
                add = True
            elif args[0].strip() == 'remove':
                add = False
            else:
                raise ValueError

            member = self.match_name(args[1].strip())
            if member is not None:
                self.game.on_team_choice(e, member, add)
            else:
                raise ValueError

        except ValueError:
            self.reply(
                e,
                "Command should be in the form of 'team [add|remove] [user]'")
Exemplo n.º 21
0
    def cmd_bring(self, args, e):
        if self.game.state == self.game.GAMESTATE_RUNNING:
            self.reply(
                e,
                _('You can\'t bring someone into a game that\'s in progress!'))
            return

        player = nm_to_n(e.source())
        if player not in self.game.players:
            self.reply(
                e,
                _('You can\'t bring someone into a game that you haven\'t even joined!'
                  ))
            return

        # Get the player that they're trying to bring:
        if len(args) != 1:
            self.reply(e, _('Usage: bring <nick>'))
            return

        if args[0] in self.game.players:
            self.reply(e, _('That player is are already in the game.'))
        elif len(self.game.players) >= 10:
            self.reply(
                e,
                _('Only 10 players are allowed to play. You\'ll have to wait'))
        elif args[0] not in self.members_in_room:
            self.reply(e,
                       _('You can\'t bring someone who isn\'t in the room!'))
            return
        else:
            self.game.players.append(args[0])

            self.reply(
                e,
                _('Nice job, you just brought %s into the game, even though they\'re probably AFK.'
                  ) % args[0])
            self.fix_modes()
Exemplo n.º 22
0
    def cmd_start(self, args, e):
        "Initialize a resistance game."
        game_starter = nm_to_n(e.source())        
        chname, chobj = self.channels.items()[0]

        if self.game.state == self.game.GAMESTATE_RUNNING:
            self.say_public("A game started by %s is in progress; "
            "that person must end it." % self.game_starter)
        
        elif self.game.state == self.game.GAMESTATE_NONE:
            self.game.reset_game()
            self.game.state = self.game.GAMESTATE_STARTING
            self.game_starter = game_starter
            self.game_starter_last_seen = time.time()
            self.game.players.append(game_starter)

            self.say_public("A new game has been started by %s; "
                "say '%s: join' to join the game."
                % (self.game_starter, self.connection.get_nickname()))
            self.say_public("%s: Say '%s: start' when everyone has joined."
                % (self.game_starter, self.connection.get_nickname()))
            self.fix_modes()

        elif self.game.state == self.game.GAMESTATE_STARTING:
            if self.game_starter and game_starter != self.game_starter:
                self.say_public("Game startup was begun by %s; "
                "that person must finish starting it." % self.game_starter)
                return
      
            self.game_starter = game_starter
            self.game_starter_last_seen = time.time()

            if len(self.game.players) < settings.min_users:
                self.say_public("Sorry, to start a game, there must be at least active %d players." % (settings.min_users))
            else:
                self.fix_modes()
                self.game.start()
Exemplo n.º 23
0
 def on_pubmsg(self, connection, event):
     cmdParts = event.arguments()[0].split()
     if len(cmdParts) > 0 and cmdParts[0] == '.':
         target = self.acl
         key = None
         last = 1
         for arg in cmdParts[1:]:
             try:
                 target = target[arg]
                 key = arg
                 last += 1
             except KeyError:
                 break
             except TypeError:
                 break
         try:
             if key is not None and hasattr(self, 'cmd_%s' % (key)):
                 authed = 'OK'
                 account = ''
                 if event.source() in self.auths:
                     account = self.auths[event.source()]['account']
                 
                 if not self._check_acl(event, cmdParts[1:last]):
                     self.communicate.notice(connection, event, 'Yout lack access to this command.')
                     authed = 'DENIED'
                 else:
                     getattr(self, 'cmd_%s' % (key))(connection, event, cmdParts[1:last], cmdParts[last:])
                 
                 self.log.command('"%s" (%s): (%s) %s' % (irclib.nm_to_n(event.source()), account, authed, ' '.join(cmdParts[1:])))
                 return
         except TypeError as te:
             print(te)
             return
         except assets.RconIdentifierError:
             self.communicate.notice(connection, event, 'No rcon available for \'%s\'.' % (cmdParts[1]))
             return
         self.communicate.notice(connection, event, 'No such command. Try \'!sf help\' for an overview of available commands.')
Exemplo n.º 24
0
 def on_quit(self, c, e):
     nick = irclib.nm_to_n(e.source())
     for target, ch in self.channels.items():
         if ch.has_user(nick):
             self._log(target, config.NOTIFY_NAME, '<%s> has quit.' % nick, PSYCHAT_MSGTYPE_SYSTEM)
Exemplo n.º 25
0
 def notice(self, connection, event, message):
     connection.notice(irclib.nm_to_n(event.source()), message)
Exemplo n.º 26
0
 def on_kick(self, c, e):
     nick_s = irclib.nm_to_n(e.source())
     nick_m = e.arguments()[0]
     because_of = e.arguments()[1]
     self._log(e.target(), config.NOTIFY_NAME, '<%s> was kicked by <%s> because of "%s".' % (nick_m, nick_s, because_of), PSYCHAT_MSGTYPE_SYSTEM)
Exemplo n.º 27
0
 def on_nick(self, c, e):
     before = irclib.nm_to_n(e.source())
     after = e.target()
     for target, ch in self.channels.items():
         if ch.has_user(before):
             self._log(target, config.NOTIFY_NAME, '<%s> is now known as <%s>.' % (before, after), PSYCHAT_MSGTYPE_SYSTEM)
Exemplo n.º 28
0
 def handle_nonplayers(self, e):
     player = nm_to_n(e.source())
     if player not in self.game.players:
         self.reply(e, "Hush, you're not playing this game.")
         return False
     return True
Exemplo n.º 29
0
 def on_part(self, c, e):
     nick = irclib.nm_to_n(e.source())
     self._log(e.target(), config.NOTIFY_NAME, '<%s> has left.' % nick, PSYCHAT_MSGTYPE_SYSTEM)
Exemplo n.º 30
0
 def handle_nonplayers(self, e):
     player = nm_to_n(e.source())
     if player not in self.game.players:
         self.reply(e, _("Hush, you're not playing this game."))
         return False
     return True
Exemplo n.º 31
0
 def cmd_end(self, args, e):
     game_ender = nm_to_n(e.source())
     self.end_game(game_ender)
Exemplo n.º 32
0
 def cmd_end(self, args, e):
     game_ender = nm_to_n(e.source())
     self.end_game(game_ender)
Exemplo n.º 33
0
 def cmd_slap(self, args, e):
     if args[0] == "all":
         slapped_players = [m for m in self.members_in_room if m != self.desired_nickname and m != nm_to_n(e.source())]
         for slapped in slapped_players:
             self.reply(e, "You slap " + member + " around a bit with a large trout.")
     else:
         self.reply(e, "You slap " + args[0] + " around a bit with a large trout.")
Exemplo n.º 34
0
 def cmd_slap(self, args, e):
     if len(args) < 1:
         self.reply(e, _("You slap yourself around a but with a large trout."))
     if args[0] == "all":
         slapped_players = [m for m in self.members_in_room if m != self.desired_nickname and m != nm_to_n(e.source())]
         for slapped in slapped_players:
             self.reply(e, _("You slap %s around a bit with a large trout.") % slapped)
     else:
         self.reply(e, _("You slap %s around a bit with a large trout.") % args[0])