コード例 #1
0
    async def update(self):
        with self.update_lock:

            print("Updating roles")
            guilds = self.bot.guilds
            guild_count = 0
            member_count = 0
            mapping_count = 0

            for guild in guilds:

                guild_count += 1
                await guild.chunk()

                role_mappings = list(data.get_role_mappings(guild.id))
                channel_mappings = list(data.get_channel_mappings(guild.id))
                mapping_count += len(role_mappings) + len(channel_mappings)

                for member in guild.members:
                    member_count += 1
                    rally_id = data.get_rally_id(member.id)
                    if rally_id:
                        balances = rally_api.get_balances(rally_id)
                        for role_mapping in role_mappings:
                            print(role_mapping)
                            await grant_deny_role_to_member(
                                role_mapping, member, balances)
                        for channel_mapping in channel_mappings:
                            await grant_deny_channel_to_member(
                                channel_mapping, member, balances)

            print("Done! Checked " + str(guild_count) + " guilds. " +
                  str(mapping_count) + " mappings. " + str(member_count) +
                  " members.")
コード例 #2
0
async def delete_mappings(mapping: ChannelMapping, guildId: str):
    data.remove_channel_mapping(
        guildId,
        mapping.coinKind,
        mapping.requiredBalance,
        mapping.channel,
    )
    return [mappings for mappings in data.get_channel_mappings(guildId)]
コード例 #3
0
ファイル: channel_cog.py プロジェクト: voanhcung/RallyRoleBot
 async def get_channel_mappings(self, ctx):
     await ctx.send(
         json.dumps(
             [
                 json.dumps(mapping)
                 for mapping in data.get_channel_mappings(ctx.guild.id)
             ]
         )
     )
コード例 #4
0
 async def get_channel_mappings(self, ctx):
     mappingsStr = "```Channel   Coin   Amount\n\n"
     for mapping in data.get_channel_mappings(ctx.guild.id):
         mappingsStr += f"{mapping[CHANNEL_NAME_KEY]}   {mapping[COIN_KIND_KEY]}   {mapping[REQUIRED_BALANCE_KEY]}\n"
     mappingsStr += "```"
     await pretty_print(
         ctx,
         mappingsStr,
         title=f"Role mappings",
         color=GREEN_COLOR,
     )
コード例 #5
0
    async def set_rally_id(self, ctx):
        member = ctx.author

        with self.update_lock:
            for guild in self.bot.guilds:
                await guild.chunk()

                if not member in guild.members:
                    continue

                role_mappings = list(data.get_role_mappings(guild.id))
                channel_mappings = list(data.get_channel_mappings(guild.id))

                rally_id = data.get_rally_id(member.id)
                if rally_id:
                    balances = rally_api.get_balances(rally_id)
                    for role_mapping in role_mappings:
                        try:
                            await grant_deny_role_to_member(
                                role_mapping, member, balances)
                        except discord.HTTPException:
                            raise errors.RequestError(
                                "network error, try again later")
                        except:
                            # Forbidden, NotFound or Invalid Argument exceptions only called when code
                            # or bot is wrongly synced / setup
                            raise errors.FatalError(
                                "bot is setup wrong, call admin")
                    for channel_mapping in channel_mappings:
                        try:
                            await grant_deny_channel_to_member(
                                channel_mapping, member, balances)
                        except discord.HTTPException:
                            raise errors.RequestError(
                                "network error, try again later")
                        except:
                            # Forbidden, NotFound or Invalid Argument exceptions only called when code
                            # or bot is wrongly synced / setup
                            raise errors.FatalError(
                                "bot is setup wrong, call admin")

            await pretty_print(
                ctx,
                "Command completed successfully!",
                title="Success",
                color=SUCCESS_COLOR,
            )
コード例 #6
0
async def read_mappings(guildId: str):
    return [mappings for mappings in data.get_channel_mappings(guildId)]