Esempio n. 1
0
    async def addRoleReaction(self, ctx, role: discord.Role,
                              reaction: typing.Union[discord.PartialEmoji,
                                                     str]):

        if type(reaction) == str and reaction not in UNICODE_EMOJI:
            return await ctx.send(f'Invalid Emote')

        server = getServerById(str(ctx.message.guild.id))
        if server.role_reaction_channel_id is None:
            return await ctx.send(f"""
            This dc server doesnt have roleReaction channel setup, type `{self._prefix()}roleReactionChannel #channel`
                """)

        if len(list(filter(lambda x: x == role,
                           ctx.message.guild.roles))) == 0:
            return await ctx.send('Invalid Role')

        res = createRoleReaction(serverId=str(ctx.message.guild.id),
                                 role=str(role.id),
                                 reaction=str(reaction))
        if not res:
            return await ctx.send(
                f'Reaction {reaction} is already set for @{role} role')

        print(f'role reaction {role}/{reaction} id in {ctx.message.guild}')
        return await ctx.send(f'Reaction {reaction} was set for @{role} role')
Esempio n. 2
0
def createRoleReaction(serverId: str, reaction: str, role: str, ses=Session()):
    server = getServerById(serverId, ses)
    if server is None:
        raise EntityNotFound
    dbRR = ses.query(RoleReaction).filter(serverId == RoleReaction.server_id,
                                          RoleReaction.reaction == reaction, RoleReaction.role == role).first()
    if dbRR is not None:
        return False
    roleReaction = RoleReaction(
        reaction=reaction, server_id=serverId, role=role)
    ses.add(roleReaction)
    ses.commit()
Esempio n. 3
0
    async def onReactionAdd(self, payload: discord.RawReactionActionEvent):
        serverId = str(payload.guild_id)
        serverDb = getServerById(serverId)
        if serverDb is not None and str(
                payload.channel_id) == serverDb.role_reaction_channel_id:
            serverRoleReaction = getRoleReactionByServerAndReaction(
                serverId, str(payload.emoji))
            if serverRoleReaction is not None:

                server = self.bot.get_guild(int(serverDb.id))
                user = server.get_member(payload.user_id)
                role = server.get_role(int(serverRoleReaction.role))
                if role not in user.roles:
                    await user.add_roles(role, atomic=True)
Esempio n. 4
0
    async def printRoleReactions(self, ctx):
        serverId = str(ctx.message.guild.id)
        server = getServerById(serverId)

        if server.role_reaction_channel_id is None:
            return await ctx.send(
                f'RoleReaction is not configured on this server.')
        chn = self.bot.get_channel(int(server.role_reaction_channel_id))
        roles = ctx.message.guild.roles
        roleReactions = getRoleReactionByServer(serverId)
        rString = []
        for rr in roleReactions:
            role = next(filter(lambda x: x.id == int(rr.role), roles))
            rString.append(
                f'  Reaction {extractEmoteText(rr.reaction)} is set for @{role.name} role'
            )
        nl = '\n'
        return await ctx.send(f"""```
The roleReaction channel is set to `#{chn}`\n
{nl.join(rString) if len(roleReactions)>0 else 'This server doesnt have any roleReactions'}\
            ```""")