Exemplo n.º 1
0
async def _removerole(ctx: SlashContext, role: discord.Role):
    userRoles = {
        user.id: user
        for user in await ctx.guild.fetch_members().flatten()
    }
    users = api.listUsers(cur, ctx.guild.id, role.id)
    api.removeRole(cur, ctx.guild.id, role.id)
    description = ' '.join(userRoles[user].mention for user in users)
    print(f"Removing role {role.id} from guild {ctx.guild.id}")
    embed = discord.Embed(title=f'Removing game',
                          description=description,
                          color=discord.Color.dark_red())
    embed.set_footer(text="Make sure you are aware!")
    if len(role.members) == 0:
        print(f"Deleting role {role.id} from guild {ctx.guild.id}")
        await role.delete(reason="No more notification subscriptions.")
        embed.add_field(name=':broken_heart: Deleting role',
                        value=f'Deleting role "{role.name}"',
                        inline=False)

    while len(description) > LIMITS['content']:
        v1, v2 = split_string(description, LIMITS['content'])
        ctx.send(content=v1)
        description = v2
    await ctx.send(content=description, embed=embed)
    con.commit()
Exemplo n.º 2
0
    async def bs_brawlers(self, ctx: SlashContext, target:str=None):
        await ctx.defer()

        fake_message = FakeMessage(
            content= "...",
            channel= ctx.channel,
            author=ctx.author,
            id=int(ctx.interaction_id),
            state=self.bot._connection
        )
        context = await self.bot.get_context(fake_message)

        user = None
        if target is None:
            user = ctx.author
        else:
            try:
                member_converter = commands.MemberConverter()
                user = await member_converter.convert(context, target)
            except commands.MemberNotFound:
                user = target

        embeds = await player_stats.get_brawlers_embeds(self.bot, context, user)
        ctx.me = context.guild.get_member(self.bot.user.id)
        ctx.bot = self.bot
        await menu(ctx=ctx, pages=embeds, controls={"⬅": prev_page, "➡": next_page}, timeout=300)
Exemplo n.º 3
0
    async def invoke(self, ctx: SlashContext, command):
        view = StringView(command)
        m = await ctx.send(f"Invoking command `{command}`...")
        ctx = commands.Context(
            prefix=bot_prefix, view=view, bot=self.bot, message=m)
        invoker = view.get_word()
        ctx.invoked_with = invoker

        if command := self.bot.all_commands.get(invoker):
            # invoke a command
            ctx.command = command
            await self.bot.invoke(ctx)
Exemplo n.º 4
0
async def _valentin(ctx: SlashContext, recipient: discord.Member):
    sender = ctx.author
    lang = os.getenv("LANG_{}".format(ctx.guild.id))
    msg = i18n.t("%{sender}’s heart burns for %{recipient}!",
                 sender=sender.mention,
                 recipient=recipient.mention,
                 locale=lang)
    await ctx.send(content=msg,
                   allowed_mentions=discord.AllowedMentions(users=True))
    with Image.open("res/templates/{}.jpg".format(lang)) as image:
        font = ImageFont.truetype("res/clegane.ttf", FONT_SIZE)
        draw = ImageDraw.Draw(image)
        sender_display_name = nick_levels.sub("", sender.display_name)
        sender_display_name = font_unavailable_chars.sub(
            "", sender_display_name)
        sender_display_name = sender_display_name.strip()
        recipient_display_name = nick_levels.sub("", recipient.display_name)
        recipient_display_name = font_unavailable_chars.sub(
            "", recipient_display_name)
        recipient_display_name = recipient_display_name.strip()
        draw.text(POSITIONS[lang]["from"],
                  sender_display_name,
                  fill=TEXT_COLOR,
                  font=font)
        draw.text(POSITIONS[lang]["to"],
                  recipient_display_name,
                  fill=TEXT_COLOR,
                  font=font)

        with io.BytesIO() as tempio:
            image.save(tempio, "jpeg", quality=JPEG_QUALITY)
            tempio.seek(0)
            # discord-py-slash-command tricks to edit original message
            ctx.responded = False
            ctx.deferred = True
            await ctx.send(
                content=msg,
                allowed_mentions=discord.AllowedMentions(users=True),
                file=discord.File(tempio, filename="flameheart.jpg"))
    lover_role = ctx.guild.get_role(
        int(os.getenv("ROLE_{}".format(ctx.guild.id))))
    try:
        if lover_role not in sender.roles:
            await sender.add_roles(lover_role)
        if lover_role not in recipient.roles:
            await recipient.add_roles(lover_role)
    except discord.Forbidden:
        logging.warning("Cannot add lover role for guild {}".format(
            repr(ctx.guild)))
Exemplo n.º 5
0
    async def player(self, ctx: SlashContext):
        await ctx.defer(hidden=True)  # prevent `failed`

        ctx.voice_client = ctx.guild.voice_client
        if await self.voicecog.join_voice(ctx):
            await cmd.play_with(ctx.guild.voice_client)
        await ctx.send(name, hidden=True)
Exemplo n.º 6
0
 async def slash_take(self, ctx: SlashContext, member: discord.Member, role: discord.Role):
     """take slash handler"""
     ctx.prefix = "/"
     if ctx.author.permissions_in(ctx.channel).manage_roles:
         await self.take(ctx, member, role=role)
     else:
         raise PermissionError("You do not have manage roles!")
Exemplo n.º 7
0
    async def on_socket_response(self, msg):
        if msg["t"] != "INTERACTION_CREATE":
            return

        d = msg["d"]
        if d["data"]["name"] != WIKI_COMMAND:
            return
        ctx = Context(SlashContext(self.slash.req, d, self.bot, self.logger))

        if "options" in d["data"] and d["data"]["options"]:
            subgroup = d["data"]["options"][0]
            wiki_group = subgroup["name"]
            if "options" in subgroup and subgroup["options"]:
                subcommand = subgroup["options"][0]
                wiki_key = subcommand["name"]
                args = {o["name"]: o["value"]
                        for o in subcommand["options"]
                        } if "options" in subcommand else {}
                self.logger.info("Calling %s/%s for guild %s", wiki_group,
                                 wiki_key, ctx.guild.id)
                try:
                    await self._topic_handler(ctx, wiki_group, wiki_key,
                                              **args)
                except Exception as ex:
                    await self.on_slash_command_error(ctx, ex)
Exemplo n.º 8
0
    async def _get_admin(self, ctx: SlashContext) -> None:
        if ctx.guild is None:

            await ctx.send(
                content=
                ("You've either ran this command in a dm or in a server without the bot user!"
                 "\nYou cannot run this command in dms"
                 "\nAnd a bot user is required for this command to work!"
                 "\nPlease invite me, invite link here: https://messagemanager.xyz/invite"
                 ),
                hidden=True,
            )
            return
        if ctx.author is None:
            ctx.author = await ctx.guild.fetch_member(ctx.author_id)

        try:
            msg = await self.logic_functions.get_admin_role_logic(
                ctx.guild, ctx.author)

        except commands.MissingPermissions as e:

            await ctx.send(content=str(e), hidden=True)
            return

        if isinstance(msg, str):
            await ctx.send(content=msg)
        else:
            await ctx.send(embeds=[msg])
Exemplo n.º 9
0
 async def search(self, ctx: SlashContext, *, query):
     async with ctx.typing():
         embed = discord.Embed(title='Search Results',
                               color=discord.Color.blue())
         for s in search(query, tld="co.in", num=6, stop=6, pause=2):
             embed.add_field(name=f'\n:link: {s}',
                             value=f'**------**',
                             inline=False)
         await ctx.send(embed=embed)
Exemplo n.º 10
0
    async def _prefix(self, ctx: SlashContext, prefix: str):
        if len(prefix) > 5:
            return ctx.send("Prefixes cannot be longer than 5 characters!")

        guild_config = await GuildConfig.get_for_guild(ctx.guild.id)
        guild_config.prefix = prefix
        guild_config.save()

        embed = ConfigEmbed(guild_config=guild_config)
        await ctx.send(content="Config has been updated.", embeds=[embed])
Exemplo n.º 11
0
async def announce(ctx: SlashContext, title = None, body = None, channel = None):

  role = discord.utils.get(ctx.guild.roles, name="Staff")

  if role in ctx.author.roles:



    #channel = client.get_channel(channel)
    embed=discord.Embed(title=title, color=0xfff714)
    embed.set_author(name="ℹ️ Announcement")
    if channel != None:
      embed.add_field(name="-", value=body, inline=True)
      embed.set_footer(text="ℹ️ Announcement created by staff.")
      await channel.send(embed=embed)
      await ctx.send("Sent!")
    else:
      ctx.send("Missing channel")
  else:
    await ctx.send("You aren't apart of staff.")
Exemplo n.º 12
0
    async def _set_admin(
        self,
        ctx: SlashContext,
        role: Optional[Union[discord.Role, int, str]] = None,
    ) -> None:
        if ctx.guild is None:

            await ctx.send(
                content=
                ("You've either ran this command in a dm or in a server without the bot user!"
                 "\nYou cannot run this command in dms"
                 "\nAnd a bot user is required for this command to work!"
                 "\nPlease invite me, invite link here: https://messagemanager.xyz/invite"
                 ),
                hidden=True,
            )
            return
        if ctx.author is None:
            ctx.author = await ctx.guild.fetch_member(ctx.author_id)

        if not isinstance(role, (int, str)) and role is not None:

            role = role.id

        if role is not None:
            role = str(role)

        try:

            msg = await self.logic_functions.set_admin_role_logic(
                ctx.guild, ctx.author, role)

        except Exception as e:

            if isinstance(
                    e,
                (
                    errors.InputContentIncorrect,
                    commands.MissingPermissions,
                    errors.WebhookChannelNotTextChannel,
                ),
            ):
                await ctx.ack(hidden=True)
                await ctx.send(content=str(e), hidden=True)
                return

            else:
                raise

        await ctx.send(embeds=[msg])
Exemplo n.º 13
0
 async def deposit_slash(self, ctx: SlashContext):
     ctx.author = await self.bot.fetch_user(ctx.author)
     r = await self._deposit(ctx)
     await ctx.send(embeds=[r[0]], content=f'```{r[1]}```')
Exemplo n.º 14
0
 async def slash_givemeremove(self, ctx: SlashContext, roles):
     """giveme remove slash handler"""
     ctx.prefix = "/"
     await self.remove(ctx, roles=roles)
Exemplo n.º 15
0
 async def tip_clog(self, ctx: SlashContext, user, amount):
     ctx.author = await self.bot.fetch_user(ctx.author)
     embed = await utility.make_embed(ctx, self.bot, color=0xffd800)
     embed = await self._tip(ctx, embed, str(user.id), amount)
     await ctx.send(embeds=[embed])
Exemplo n.º 16
0
 async def claim_slash(self, ctx: SlashContext):
     ctx.author = await self.bot.fetch_user(ctx.author)
     embed = await self._make_claim(ctx)
     await ctx.send(embeds=[embed])
Exemplo n.º 17
0
    async def leave(self, ctx: SlashContext):
        await ctx.defer(hidden=True)

        ctx.voice_client = ctx.guild.voice_client
        await self.voicecog.leave_voice(ctx)
        await ctx.send("Goodbye!", hidden=True)
Exemplo n.º 18
0
    async def join(self, ctx: SlashContext):
        await ctx.defer(hidden=True)

        ctx.voice_client = ctx.guild.voice_client
        await self.voicecog.join_voice(ctx)
        await ctx.send("Hello!", hidden=True)
Exemplo n.º 19
0
 async def withdrawall_slash(self, ctx: SlashContext, address):
     ctx.author = await self.bot.fetch_user(ctx.author)
     embed = await self._withdrawall(ctx, address)
     await ctx.send(embeds=[embed])
Exemplo n.º 20
0
 async def balance_clog(self, ctx: SlashContext):
     ctx.author = await self.bot.fetch_user(ctx.author)
     embed = await self._balance(ctx)
     await ctx.send(embeds=[embed])