Exemplo n.º 1
0
class Starboard(discord.SlashCommand, parent=Setup):
    '''This adds starboard system to your server'''

    channel: GuildChannel = discord.application_command_option(
        channel_types=[discord.TextChannel],
        description="The channel where the starred message will go")
    stars: typing.Optional[int] = discord.application_command_option(
        description=
        "Minimum number of stars required before posting it to the specified channel",
        default=5)
    self_star: typing.Optional[bool] = discord.application_command_option(
        description="Whether self  starring of message should be there or not",
        default=False)
    ignore_nsfw: typing.Optional[bool] = discord.application_command_option(
        description="Whether to ignore NSFW channels or not", default=True)

    async def callback(self, response: discord.SlashCommandResponse):
        dict_to_add = {
            "starboard": {
                "channel": response.options.channel.id,
                "no_of_stars": response.options.stars,
                "self_star": response.options.self_star,
                "ignore_nsfw": response.options.ignore_nsfw
            }
        }
        await self.parent.cog.add_and_check_data(dict_to_add,
                                                 response.interaction.guild,
                                                 'setupvar')
        await response.send_message(
            f'Done! Added `starboard channel` as {response.options.channel.mention} with minimum `{response.options.stars} stars` requirement'
        )
Exemplo n.º 2
0
class Add(discord.SlashCommand, parent=Setup):
    '''This adds logging of the some things in the specified text channel'''

    add_type: typing.Literal["ban", "feedback", "warns",
                             "unban"] = discord.application_command_option(
                                 description="which to log",
                                 name="type",
                                 default=None)
    channel: GuildChannel = discord.application_command_option(
        channel_types=[discord.TextChannel], description="The logging channel")

    async def callback(self, response: discord.SlashCommandResponse):
        dict_to_add = {str(response.options.type): response.options.channel.id}
        await self.parent.cog.add_and_check_data(dict_to_add,
                                                 response.interaction.guild,
                                                 'setupvar')
        await response.send_message(
            f'Done! `Added {response.options.type} logging` to {response.options.channel.mention}'
        )
Exemplo n.º 3
0
class Support(discord.SlashCommand, parent=Setup):
    '''This adds support system to your server'''

    channel: GuildChannel = discord.application_command_option(
        channel_types=[discord.TextChannel],
        description="The support logging channel")
    role: discord.Role = discord.application_command_option(
        description=
        "The role using which memebrs can access that support channel")

    async def callback(self, response: discord.SlashCommandResponse):
        dict_to_add = {
            "support": [response.options.channel.id, response.options.role.id]
        }
        await self.parent.cog.add_and_check_data(dict_to_add,
                                                 response.interaction.guild,
                                                 'setupvar')
        await response.send_message(
            f'Done! Added `support logging` to {response.options.channel.mention} with {response.options.role.mention} `role`'
        )
Exemplo n.º 4
0
class UserInfoSlash(discord.SlashCommand, name="user"):
    """Get some basic user info"""

    user: discord.Member = discord.application_command_option(
        description="user")

    def __init__(self, cog):
        self.cog = cog

    async def callback(self, response: discord.SlashCommandResponse):
        await response.send_message(embed=await userinfo(
            response.options.user, response.interaction.guild, self.cog.bot))
Exemplo n.º 5
0
class User(discord.SlashCommand, parent=Blacklist):
    '''Adds user to the blacklist'''
    id: str = discord.application_command_option(
        description="The user to add to the blacklist", default=None)
    reason: typing.Optional[str] = discord.application_command_option(
        description='Reason', default=None)

    async def callback(self, response: discord.SlashCommandResponse) -> None:
        user_id = response.options.id
        if not str(user_id).isdigit():
            return await response.send_message('Not a valid userid',
                                               ephemeral=True)
        if self.parent.cog.bot.get_user(int(user_id)):
            database = await self.parent.cog.database_class_user()
            await database.set(user_id, response.options.reason)
            self.parent.cog.bot.blacklist.append(int(user_id))
            await response.send_message('User added to the blacklist',
                                        ephemeral=True)
            return
        else:
            await response.send_message('User not found', ephemeral=True)
Exemplo n.º 6
0
class BadLinks(discord.SlashCommand, parent=Setup):
    '''Checks against the scam links and take necessary action if stated'''
    option: bool = discord.application_command_option(
        description="Enable or Disable", default=True)
    action: typing.Optional[
        typing.Literal["ban", "mute", "timeout", "kick",
                       "log"]] = discord.application_command_option(
                           description="What kind of action to take",
                           default=None)
    channel: typing.Optional[
        GuildChannel] = discord.application_command_option(
            channel_types=[discord.TextChannel],
            description="Log channel",
            default=None)

    async def callback(self, response: discord.SlashCommandResponse):
        if not response.options.option:
            database = await self.parent.cog.database_class()
            guild_dict = await database.get(response.interaction.guild.id)
            if guild_dict is None:
                return
            guild_dict.pop('badlinks')
            await database.set(response.interaction.guild.id, guild_dict)
            await response.send_message('Badlink system turned off!')
            return
        await self.parent.cog.add_and_check_data(
            {
                "badlinks": {
                    "option":
                    response.options.option,
                    "action":
                    response.options.action,
                    "logging_channel":
                    response.options.channel.id if response.options.channel
                    is not None else response.options.channel
                }
            }, response.interaction.guild, 'setupvar')
        await response.send_message(
            f'Done! If I detect any scam link then I `delete` that and will do a `{response.options.action}` action'
        )
Exemplo n.º 7
0
class Server(discord.SlashCommand, parent=Blacklist):
    '''Adds guild to the blacklist'''
    id: str = discord.application_command_option(
        description="The server which is to be added", default=None)
    reason: typing.Optional[str] = discord.application_command_option(
        description='Reason', default=None)

    async def callback(self, response: discord.SlashCommandResponse) -> None:
        server_id = response.options.id or response.guild_id
        if not str(server_id).isdigit():
            return await response.send_message('Not a valid serverid',
                                               ephemeral=True)
        guild = self.parent.cog.bot.get_guild(int(server_id))
        if guild is not None:
            database = await self.parent.cog.database_class_server()
            await database.set(server_id, response.options.reason)
            self.parent.cog.bot.blacklist.append(int(server_id))
            channel = await self.parent.cog.bot.get_welcome_channel(guild)
            embed = ErrorEmbed(title=f'Left {guild.name}')
            embed.description = f'I have to leave the `{guild.name}` because it was marked as a `blacklist guild` by my developer. For further queries please contact my developer.'
            embed.add_field(
                name='Developer',
                value=
                f'[{self.parent.cog.bot.get_user(self.parent.cog.bot.owner_id)}](https://discord.com/users/{self.parent.cog.bot.owner_id})'
            )
            embed.add_field(
                name="Support Server",
                value=f"https://discord.gg/{LinksAndVars.invite_code.value}",
            )
            await channel.send(embed=embed)
            await guild.leave()
            log.info(f'Left guild {guild.id} [Marked as spam]')
            await response.send_message('Server added to the blacklist',
                                        ephemeral=True)
            return
        else:
            return await response.send_message('Server not found',
                                               ephemeral=True)
Exemplo n.º 8
0
class Activities(discord.SlashCommand):
    """Get access to discord beta activities feature"""

    activities: typing.Literal[
        "youtube", "poker", "chess", "betrayal", "fishing", "letter-league",
        "word-snack", "sketch-heads", "spellcast", "awkword",
        "checkers"] = discord.application_command_option(
            description="The type of activity",
            default="youtube",
        )

    voice_channel: GuildChannel = application_command_option(
        channel_types=[VoiceChannel],
        description="A voice channel in the selected activity will start",
        name="channel")

    def __init__(self, cog):
        self.cog = cog

    async def callback(self, response: discord.SlashCommandResponse):
        link = await self.cog.bot.togetherControl.create_link(
            response.options.channel.id, str(response.options.activities))
        await response.send_message(f"Click the blue link!\n{link}")
Exemplo n.º 9
0
class Vocaloids(discord.SlashCommand):
    '''Get kawaii pictures of different vocaloids'''
    vocaloid: typing.Optional[typing.Literal[
        "rin", "una", "gumi", "ia", "luka", "fukase", "miku", "len", "kaito",
        "teto", "meiko", "yukari", "miki", "lily", "mayu", "aoki", "zola",
        "diva"]] = discord.application_command_option(
            description="Select you favourite vocaloid",
            default="miku",
        )

    def __init__(self, cog):
        self.cog = cog

    async def callback(self, response: discord.SlashCommandResponse):
        await response.send_message(
            embed=await meek_api(response.options.vocaloid))
Exemplo n.º 10
0
class Fetch(discord.SlashCommand, parent=Blacklist):
    '''Fetches data from the blacklist list of users and server'''
    id: str = discord.application_command_option(
        description="The server/user data which is to be fetched",
        default=None)

    async def callback(self, response: discord.SlashCommandResponse) -> None:
        database_user = await self.parent.cog.database_class_user()
        database_server = await self.parent.cog.database_class_server()
        user_check = await database_user.get(response.options.id)
        server_check = await database_server.get(response.options.id)
        if user_check is None and server_check is None:
            return await response.send_message(
                embed=ErrorEmbed(title='No data found'), ephemeral=True)
        return await response.send_message(embed=SuccessEmbed(
            title=response.options.id,
            description=
            f'Found in {database_user._Database__channel.mention if user_check is not None else database_server._Database__channel.mention}\n\n **Reason**\n```\n{user_check or server_check}\n```'
        ))
Exemplo n.º 11
0
class Badurls(discord.SlashCommand, name="badurls"):
    """Check if a text has a malicious url or not from a extensive list 60k+ flagged domains"""
    name = "bad urls"

    content = discord.application_command_option(
        description='The text, url or a list of urls to check', type=str)

    @content.autocomplete
    async def content_autocomplete(
            self, response: discord.AutocompleteResponse
    ) -> typing.AsyncIterator[str]:
        async with aiohttp.ClientSession() as session:
            async with session.get(LinksAndVars.bad_links.value) as resp:
                list_of_bad_domains = (await resp.text()).split('\n')

        end = random.randint(25, len(list_of_bad_domains))
        for domain in list_of_bad_domains[end - 25:end]:
            if response.value.lower() in domain.lower():
                yield domain

    def __init__(self, cog):
        self.cog = cog

    async def callback(self, response: discord.SlashCommandResponse):
        detected_urls = await detect_bad_domains(response.options.content)
        if len(detected_urls) != 0:
            embed = ErrorEmbed(title='SCAM/PHISHING/ADULT LINK(S) DETECTED')
            detected_string = '\n'.join(
                [f'- ||{i}||' for i in set(detected_urls)])
            embed.description = f'The following scam url(s) were detected:\n{detected_string}'
            embed.set_author(
                name=response.interaction.user.display_name,
                icon_url=response.interaction.user.display_avatar.url)
            await response.send_message(embed=embed, ephemeral=True)
            return
        await response.send_message(
            embed=SuccessEmbed(title="The url or the text message is safe!"),
            ephemeral=True)
Exemplo n.º 12
0
class Delete(discord.SlashCommand, parent=Blacklist):
    '''Delete the data if found blacklist list'''

    id: str = discord.application_command_option(
        description="The server/user data which is to be fetched",
        default=None)

    async def callback(self, response: discord.SlashCommandResponse) -> None:
        if not str(response.options.id).isdigit():
            return await response.send_message('Not a valid serverid/userid',
                                               ephemeral=True)
        await response.send_message(
            'If data is available then will be removed from the blacklist',
            ephemeral=True)
        database_user = await self.parent.cog.database_class_user()
        database_server = await self.parent.cog.database_class_server()
        await database_user.delete(response.options.id)
        await database_server.delete(response.options.id)

        try:
            self.parent.cog.bot.blacklist.remove(int(response.options.id))
        except ValueError:
            pass
Exemplo n.º 13
0
class AntiRaid(discord.SlashCommand):
    """Enable or disable Antiraid system for the server"""
    switch: typing.Literal["on", "strict",
                           "off"] = discord.application_command_option(
                               description="Antiraid different modes",
                               default="on")
    channel: GuildChannel = discord.application_command_option(
        channel_types=[discord.TextChannel],
        description="Channel to broadcast join messages")

    def __init__(self, cog):
        self.cog = cog

    async def command_check(self,
                            response: discord.SlashCommandResponse) -> bool:
        if response.channel.permissions_for(response.user).manage_guild:
            return True
        else:
            await response.send_message(
                "You don't have the `Manage Guild` permission", ephemeral=True)
            return False

    async def callback(self, response: discord.SlashCommandResponse):
        database = await self.cog.bot.db.new(
            Database.database_category_name.value,
            Database.antiraid_channel_name.value)
        switch = response.options.switch
        if switch.lower() == "off":
            await database.delete(response.interaction.guild_id)
            try:
                await response.interaction.guild.edit(
                    verification_level=discord.VerificationLevel.low)
                await response.send_message(
                    "Raid mode disabled. No longer broadcasting join messages.",
                    ephemeral=True)
            except discord.HTTPException:
                await response.send_message(
                    "\N{WARNING SIGN} Could not set verification level.",
                    ephemeral=True)
            return
        if switch.lower() == "strict":
            try:
                await response.interaction.guild.edit(
                    verification_level=discord.VerificationLevel.high)
                update_dict = {
                    "raid_mode": RaidMode.strict.value,
                    "broadcast_channel": response.options.channel.id
                }
                await self.cog.add_and_check_data(update_dict,
                                                  response.interaction.guild,
                                                  'antiraid')
                await response.send_message(
                    f"Raid mode enabled. Broadcasting join messages to {response.options.channel.mention}.",
                    ephemeral=True)
            except discord.HTTPException:
                await response.send_message(
                    "\N{WARNING SIGN} Could not set verification level.",
                    ephemeral=True)
            return
        try:
            await response.interaction.guild.edit(
                verification_level=discord.VerificationLevel.medium)
            update_dict = {
                "raid_mode": RaidMode.on.value,
                "broadcast_channel": response.options.channel.id
            }
            await self.cog.add_and_check_data(update_dict,
                                              response.interaction.guild,
                                              'antiraid')
            await response.send_message(
                f"Raid mode enabled. Broadcasting join messages to {response.options.channel.mention}.",
                ephemeral=True)
        except discord.HTTPException:
            await response.send_message(
                "\N{WARNING SIGN} Could not set verification level.",
                ephemeral=True)