예제 #1
0
    def on_bot_shutdown(self):
        CacheHelper.save_guilds(self.guild_list)
        logger = CacheHelper.get_logger("ShutdownHook")
        logger.zilean("Bot Shutdown - Guild List saved successfully")

        # Send restart messages to those who have bound the bot to a channel
        ''' channel_binds = LiveDataHelper.load_guild_binds()
예제 #2
0
    def on_guild_remove(self, event):
        guild_list = self.guild_list
        guild = guild_list[str(event.id)]
        guild_list.pop(str(event.id))

        logger = CacheHelper.get_logger("GuildRemove")
        logger.zilean("Guild Removed: " + guild[0] + " " + str(guild[1]))

        channel_binds = LiveDataHelper.load_guild_binds()
        channel_bind = channel_binds.pop(str(event.id), None)

        if channel_bind:
            logger.zilean("Guild-Channel bind has been removed for " + guild[0] + " " + str(guild[1]))

        LiveDataHelper.save_guild_binds(channel_binds)
예제 #3
0
    def on_schedule_track(self):
        tracker = self.tracker
        channel_binds = LiveDataHelper.load_guild_binds()
        game_info = GameInfo(self.league_helper)

        if len(tracker) == 0:
            return

        for guild_id in channel_binds.keys():
            guild_id = str(guild_id)
            if self._guild_is_tracked(guild_id):
                channel = self.bot.client.state.channels.get(
                    channel_binds[guild_id])
                if channel is not None:  # Prevents errors if the bot has left a guild, but the guild id still persits in the binds
                    summoner_list = tracker[guild_id]
                    logger = CacheHelper.get_logger("TrackerMessage")
                    self._display_track(tracker[guild_id], channel)
                    logger.zilean(
                        "Tracker: " + guild_id + " " +
                        self.bot.client.state.guilds.get(int(guild_id)).name)
예제 #4
0
    def _display_track(self, summoner_list, channel):
        game_found = False
        has_live_games = False
        summoner_names = ""
        regions = ""
        in_game = ""
        footer = ""

        connection_failure = False
        for summoner in summoner_list:
            summoner_failed = False
            auto_display = summoner[3]
            summoner_names += summoner[1] + "\n"
            regions += summoner[2] + "\n"

            try:
                spectate_info = self.league_helper.user_in_game(
                    summoner[2], summoner[0])
            except ConnectionError as e:
                logger = CacheHelper.get_logger("TrackerError")
                logger.zilean("Could not connect to the Riot API. Summoner: " +
                              summoner[1] + "Channel: " + channel.name)
                summoner_failed = True
                connection_failure = True

            if spectate_info and not summoner_failed:
                in_game += "**Yes** | " + self.boolMsg(auto_display) + "\n"
                if auto_display:
                    game_info = GameInfo(self.league_helper)
                    game_info.display_live_game(channel, summoner[2],
                                                spectate_info)
                has_live_games = True
            elif not summoner_failed:
                in_game += "No | " + self.boolMsg(auto_display) + "\n"
            else:
                in_game += "Summoner info cannot be retrieved at this time\n"

        if connection_failure:
            footer = "Error retrieving one or more summoners info"
        if not has_live_games:
            footer = "No one is currently in a live game :("
        else:
            footer = "To view a summoner in game use ~game_info <region> <summoner_name>"

        description = "This message is automatically displayed every " + str(int(TRACKER_SCHEDULE/60)) + " minutes!" + \
                            "\n If auto-display is turned on for a summoner their game is automatically displayed"

        embed = CacheHelper.getZileanEmbed(
            title=":eye: Tracking Live Games... :eye:",
            description=description,
            footer=footer)
        embed.add_field(name="Summoner Name",
                        value=summoner_names,
                        inline=True)
        embed.add_field(name="Region", value=regions, inline=True)
        embed.add_field(name="In Game | Auto-Display",
                        value=in_game,
                        inline=True)

        if connection_failure:
            embed.add_field(
                name="Connection Issue",
                value=
                "One or more summoners info could not be retrieved. Please try again in a few minutes."
            )

        try:
            channel.send_message(embed=embed)
        except ConnectionError as e:
            logger = CacheHelper.get_logger("TrackerError")
            logger.zilean(
                "Tracker message failed to send. Could not connect to the Discord API"
            )
        except APIException as e:
            logger = CacheHelper.get_logger("TrackerError")
            logger.zilean("APIException - " + str(e.status_code))
예제 #5
0
 def update_command_list(self, command_list):
     with open("docs/commandList.json", "w") as data_file:
         json.dump(command_list, data_file)
     logger = CacheHelper.get_logger("CommandList")
     logger.zilean("Command List Generated")
예제 #6
0
 def on_guild_create(self, event):
     self.guild_list[str(event.guild.id)] = (event.guild.name, event.guild.id)
     logger = CacheHelper.get_logger("GuildCreate")
     logger.zilean("New Guild Created: " + event.guild.name + " " + str(event.guild.id))