示例#1
0
def create_event_button(bot: Bot, name: str, event: Event):
    async def new_button(self, button: Button, inter: MessageInteraction):
        member = inter.author
        guild = inter.guild
        for role in guild.roles:
            if role.name.lower() == name.replace("_", " "):
                break
        else:
            return

        if role in member.roles:
            await member.remove_roles(role)
            opt = "out"
        else:
            await member.add_roles(role)
            opt = "in"

        await inter.response.send_message(
            f"I have successfully opted you {opt} for {name} notifications!",
            ephemeral=True)

    icon = bot.get_emoji(event.icon)
    new_button.__name__ = name

    return button(custom_id=f"event {name}", emoji=icon)(new_button)
示例#2
0
async def get_user(bot: commands.Bot, user_id: int) -> Optional[discord.User]:
    user = bot.get_user(user_id)
    if user is None:
        try:
            user = await bot.fetch_user(user_id)
        except:
            pass
    return user
示例#3
0
    def __init__(self, bot: commands.Bot):
        self.bot = bot
        self.old_help_command = bot.help_command
        bot.help_command = PaginatedHelpCommand()
        bot.help_command.cog = self

        self.activities = Activities(self.bot)
        self.update_presence.start()
示例#4
0
async def get_guild(bot: commands.Bot,
                    guild_id: int) -> Optional[discord.Guild]:
    guild = bot.get_guild(guild_id)
    if guild is None:
        try:
            guild = await bot.fetch_guild(guild_id)
        except:
            pass
    return guild
    async def from_payload(cls, bot: Bot,
                           payload: discord.RawReactionActionEvent):
        channel = bot.get_channel(payload.channel_id)
        if channel is None:
            return None

        if isinstance(channel, discord.DMChannel):
            return None

        guild = channel.guild
        if guild is None:
            return None

        member = payload.member if payload.member is not None else guild.get_member(
            payload.user_id)
        if member is None or member.bot:
            return None

        try:
            message: discord.Message = await channel.fetch_message(
                payload.message_id)
            if message is None:
                return None
        except discord.errors.NotFound:
            return None

        reply_to = None
        if message is not None and message.reference is not None and message.reference.message_id is not None:
            try:
                reply_to = await channel.fetch_message(
                    message.reference.message_id)
            except discord.errors.NotFound:
                pass

        if payload.emoji.is_custom_emoji():
            emoji = bot.get_emoji(payload.emoji.id)
            if emoji is None:
                emoji = payload.emoji
        else:
            emoji = payload.emoji.name

        return cls(channel, guild, member, message, reply_to, emoji)
示例#6
0
    async def from_payload(bot: Bot, payload: disnake.RawReactionActionEvent):
        channel: disnake.TextChannel = bot.get_channel(payload.channel_id)
        if channel is None:
            return None

        if channel.type is disnake.ChannelType.text:
            guild = channel.guild
        else:
            guild = bot.get_guild(config.guild_id)
            if guild is None:
                raise Exception("Nemůžu najít guildu podle config.guild_id")

        member = payload.member if payload.member is not None else guild.get_member(payload.user_id)
        if member is None or member.bot:
            return None

        try:
            message: disnake.Message = await channel.fetch_message(payload.message_id)

            if message is None:
                return None
        except disnake.errors.NotFound:
            return None

        reply_to = None
        if message is not None and message.reference is not None and message.reference.message_id is not None:
            try:
                reply_to = await channel.fetch_message(message.reference.message_id)
            except disnake.errors.NotFound:
                pass  # Reply is there optional.

        if payload.emoji.is_custom_emoji():
            emoji = bot.get_emoji(payload.emoji.id)
            if emoji is None:
                emoji = payload.emoji
        else:
            emoji = payload.emoji.name

        return ReactionContext(channel, guild, member, message, reply_to, emoji)
示例#7
0
文件: vote.py 项目: Misha12/rubbergod
async def get_or_fetch_user(bot: Bot, user_id):
    user = bot.get_user(user_id)
    if user is None:
        user = await bot.fetch_user(user_id)
    return user
示例#8
0
def setup(bot: commands.Bot) -> None:
    """Load the Github cog."""
    bot.add_cog(Github(bot))
示例#9
0
def setup(bot: commands.Bot):
    bot.add_cog(DueDiligenceCommands(bot))
示例#10
0
def setup(bot: commands.Bot):
    bot.add_cog(DarkPoolShortsCommands(bot))
示例#11
0
def setup(bot: commands.Bot):
    """
    The setup function defining the jishaku.cog and jishaku extensions.
    """

    bot.add_cog(Jishaku(bot=bot))
示例#12
0
def setup(bot: Bot) -> None:
    """Loading the Gurkcraft cog."""
    bot.add_cog(Gurkcraft(bot))
示例#13
0
def setup(bot: commands.Bot) -> None:
    """Load the Cog."""
    bot.add_cog(MakeGurkan(bot))
示例#14
0
def setup(bot: commands.Bot):
    bot.add_cog(StocksSIACommands(bot))
示例#15
0
文件: bonker.py 项目: gurkult/gurkbot
def setup(bot: commands.Bot) -> None:
    """Load the Bonk cog."""
    bot.add_cog(Bonk(bot))
示例#16
0
def setup(bot: commands.Bot) -> None:
    """Error handler Cog load."""
    bot.add_cog(CommandErrorHandler(bot))
示例#17
0
def setup(bot: commands.Bot):
    bot.add_cog(DiscoverCommands(bot))
示例#18
0
def setup(bot: commands.Bot):
    bot.add_cog(EconomyCommands(bot))
示例#19
0
def setup(bot: commands.Bot):
    bot.add_cog(GovernmentCommands(bot))
示例#20
0
def setup(bot: commands.Bot):
    bot.add_cog(Extension_Manager(bot))
示例#21
0
def setup(bot: commands.Bot):
    bot.add_cog(Guild_Cog(bot))
示例#22
0
def setup(bot: commands.Bot):
    bot.add_cog(HoyolabApiCog(bot))
示例#23
0
文件: vote.py 项目: Misha12/rubbergod
async def get_or_fetch_channel(bot: Bot, channel_id):
    channel = bot.get_channel(channel_id)
    if channel is None:
        channel = await bot.fetch_channel(channel_id)
    return channel
示例#24
0
def setup(bot: commands.Bot):
    bot.add_cog(CmdsCommands(bot))
示例#25
0
def setup(bot: commands.Bot):
    bot.add_cog(EtfCommands(bot))
示例#26
0
def setup(bot: commands.Bot):
    bot.add_cog(ScreenerCommands(bot))
示例#27
0
def setup(bot: commands.Bot):
    bot.add_cog(TechnicalAnalysisCommands(bot))
示例#28
0
def setup(bot: commands.Bot):
    bot.add_cog(Help_Cog(bot))