From 5cd37701cdce24f8c5d8564b36afdbaa02ac2180 Mon Sep 17 00:00:00 2001 From: FO-nTTaX Date: Thu, 20 Oct 2022 04:25:02 +0200 Subject: [PATCH] enforce code style --- .github/workflows/codestyle.yml | 12 + ftsbot/cogs/antispam.py | 80 +++++- ftsbot/cogs/channelmoderation.py | 131 +++++++-- ftsbot/cogs/presence.py | 14 +- ftsbot/cogs/rolecommands.py | 111 ++++++-- ftsbot/cogs/textcommands.py | 446 ++++++++++++++++++++++++------ ftsbot/cogs/wikicommands.py | 95 +++++-- ftsbot/config.py | 6 +- ftsbot/functions/autocomplete.py | 12 +- ftsbot/functions/rolefunctions.py | 10 +- ftsbot/functions/wikifunctions.py | 101 ++++++- ftsbot/liquipediabot.py | 17 +- ftsbot/ui/reportform.py | 44 ++- tox.ini | 6 + 14 files changed, 899 insertions(+), 186 deletions(-) create mode 100644 .github/workflows/codestyle.yml create mode 100644 tox.ini diff --git a/.github/workflows/codestyle.yml b/.github/workflows/codestyle.yml new file mode 100644 index 0000000..c229372 --- /dev/null +++ b/.github/workflows/codestyle.yml @@ -0,0 +1,12 @@ +name: Python Style Checker + +on: [ push, pull_request, workflow_dispatch ] + +jobs: + test-python: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Python Style Checker + uses: andymckay/pycodestyle-action@0.1.3 diff --git a/ftsbot/cogs/antispam.py b/ftsbot/cogs/antispam.py index edb1704..3e9a70c 100644 --- a/ftsbot/cogs/antispam.py +++ b/ftsbot/cogs/antispam.py @@ -12,8 +12,14 @@ from ftsbot.ui.reportform import reportform import time -class antispam(commands.Cog): - def __init__(self, bot): + +class antispam( + commands.Cog +): + def __init__( + self, + bot + ): self.bot = bot self.reactionspammers = {} self.pingspammers = {} @@ -24,21 +30,54 @@ def __init__(self, bot): ) self.bot.tree.add_command(self.ctx_report) - async def cog_unload(self) -> None: + async def cog_unload( + self + ) -> None: self.bot.tree.remove_command(self.ctx_report.name, type=self.ctx_report.type) @commands.Cog.listener() - async def on_message(self, message): + async def on_message( + self, + message + ): if 'liquidpedia' in message.content.lower(): - await message.channel.send(embed=discord.Embed(colour=discord.Colour(0xff0000), description='It is **Liquipedia**, only one d in the name! Naughty-counter of ' + message.author.name + ' has been incremented.')) - if hasattr(message.author, 'joined_at') and (discord.utils.utcnow() - message.author.joined_at).days <= 7: + await message.channel.send( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description=( + 'It is **Liquipedia**, only one d in the name! Naughty-counter of ' + + message.author.name + ' has been incremented.' + ) + ) + ) + if ( + hasattr(message.author, 'joined_at') + and (discord.utils.utcnow() - message.author.joined_at).days <= 7 + ): for role in message.role_mentions: if role.name == 'Liquipedia Admins': - await message.channel.send('Hello ' + message.author.mention + ', you seem to be new to our server and you have messaged Liquipedia Administrators. If your issue is not of private nature, please just write it in the channel for the game it is about.') - if len(message.mentions) > 10 and hasattr(message.author, 'joined_at') and (discord.utils.utcnow() - message.author.joined_at).days <= 100: + await message.channel.send( + 'Hello ' + + message.author.mention + + ', you seem to be new to our server and you have messaged Liquipedia Administrators. ' + + 'If your issue is not of private nature, please just write it in the channel for the game it is about.' + ) + if ( + len(message.mentions) > 10 + and hasattr(message.author, 'joined_at') + and (discord.utils.utcnow() - message.author.joined_at).days <= 100 + ): has_exception_role = False for role in message.author.roles: - if role.name in {'Discord Admins', 'Liquipedia Employee', 'Administrator', 'Editor', 'Reviewer', 'Silver Plus', 'Industry Person'}: + if role.name in { + 'Discord Admins', + 'Liquipedia Employee', + 'Administrator', + 'Editor', + 'Reviewer', + 'Silver Plus', + 'Industry Person' + }: has_exception_role = True break if not has_exception_role: @@ -51,7 +90,10 @@ async def on_message(self, message): pass @commands.Cog.listener() - async def on_member_join(self, member): + async def on_member_join( + self, + member + ): if 'twitter.com/h0nde' in member.name.lower() or 'twitter.com/h0nde' in member.nick.lower(): try: await member.ban(reason='Automated ban, spam') @@ -59,14 +101,20 @@ async def on_member_join(self, member): pass @commands.Cog.listener() - async def on_ready(self): + async def on_ready( + self + ): while True: - await asyncio.sleep(60) # Sets the time after which the reaction and ping spam lists are cleared + await asyncio.sleep(60) # Sets the time after which the reaction and ping spam lists are cleared self.reactionspammers.clear() self.pingspammers.clear() @commands.Cog.listener() - async def on_reaction_add(self, reaction, user): + async def on_reaction_add( + self, + reaction, + user + ): # Check if user joined within last 7 days if hasattr(reaction.message.author, 'joined_at') and (discord.utils.utcnow() - user.joined_at).days <= 7: if user.id not in self.reactionspammers: @@ -79,6 +127,10 @@ async def on_reaction_add(self, reaction, user): except discord.Forbidden: pass - async def report(self, interaction: discord.Interaction, message: discord.Message): + async def report( + self, + interaction: discord.Interaction, + message: discord.Message + ): form = reportform(self.bot, message) await interaction.response.send_modal(form) diff --git a/ftsbot/cogs/channelmoderation.py b/ftsbot/cogs/channelmoderation.py index 4568a8e..e631b92 100644 --- a/ftsbot/cogs/channelmoderation.py +++ b/ftsbot/cogs/channelmoderation.py @@ -10,34 +10,75 @@ from ftsbot import config, data import typing -class channelmoderation(commands.Cog): - def __init__(self, bot): + +class channelmoderation( + commands.Cog +): + def __init__( + self, + bot + ): self.bot = bot - @app_commands.command(description='Purge channel (admin only)') + @app_commands.command( + description='Purge channel (admin only)' + ) @app_commands.describe( channel='Which channel do you want to purge?', ) - @app_commands.checks.has_any_role('Discord Admins', 'Liquipedia Employee', 'Administrator') + @app_commands.checks.has_any_role( + 'Discord Admins', + 'Liquipedia Employee', + 'Administrator' + ) @app_commands.guild_only() - async def channelpurge(self, interaction: discord.Interaction, channel: typing.Optional[discord.TextChannel]): + async def channelpurge( + self, + interaction: discord.Interaction, + channel: typing.Optional[discord.TextChannel] + ): if channel is None: channel = interaction.channel - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description='Channel ' + channel.name + ' is being purged')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description='Channel ' + channel.name + ' is being purged' + ) + ) if channel is None or not channel.name.startswith('temp_'): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='Invalid channel')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='Invalid channel' + ) + ) else: async for message in channel.history(): await message.delete() - @app_commands.command(description='Creates a temp. private channel and invites the specified user to it (admin only)') + @app_commands.command( + description='Creates a temp. private channel and invites the specified user to it (admin only)' + ) @app_commands.describe( member='Who do you want to invite?', ) - @app_commands.checks.has_any_role('Discord Admins', 'Liquipedia Employee', 'Administrator') + @app_commands.checks.has_any_role( + 'Discord Admins', + 'Liquipedia Employee', + 'Administrator' + ) @app_commands.guild_only() - async def channelcreate(self, interaction: discord.Interaction, member: discord.Member): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description='Channel with ' + member.name + ' is being created')) + async def channelcreate( + self, + interaction: discord.Interaction, + member: discord.Member + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description='Channel with ' + member.name + ' is being created' + ) + ) guild = interaction.guild admin_role1 = discord.utils.get(guild.roles, name='Discord Admins') admin_role2 = discord.utils.get(guild.roles, name='Liquipedia Employee') @@ -53,22 +94,46 @@ async def channelcreate(self, interaction: discord.Interaction, member: discord. overwrites[admin_role2] = discord.PermissionOverwrite(read_messages=True) if admin_role3 is not None: overwrites[admin_role3] = discord.PermissionOverwrite(read_messages=True) - channel = await guild.create_text_channel('temp_' + member.name, overwrites=overwrites, category=self.bot.get_channel(int(config.privcat))) + channel = await guild.create_text_channel( + 'temp_' + member.name, + overwrites=overwrites, + category=self.bot.get_channel(int(config.privcat)) + ) await channel.send('This channel was created to discuss the private request of ' + member.mention) - @app_commands.command(description='Copies the specified temp. or active channel to the archive (admin only)') + @app_commands.command( + description='Copies the specified temp. or active channel to the archive (admin only)' + ) @app_commands.describe( channel='Where do you want to copy things from?', ) - @app_commands.checks.has_any_role('Discord Admins', 'Liquipedia Employee', 'Administrator') + @app_commands.checks.has_any_role( + 'Discord Admins', + 'Liquipedia Employee', + 'Administrator' + ) @app_commands.guild_only() - async def channelcopy(self, interaction: discord.Interaction, channel: typing.Optional[discord.TextChannel]): + async def channelcopy( + self, + interaction: discord.Interaction, + channel: typing.Optional[discord.TextChannel] + ): if channel is None: channel = interaction.channel if channel is None or not channel.name.startswith('temp_'): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='Invalid channel')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='Invalid channel' + ) + ) else: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description='Messages have been archived')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description='Messages have been archived' + ) + ) emptyarray = [] logtarget = self.bot.get_channel(config.logtarget) async for message in channel.history(limit=10000, oldest_first=True): @@ -79,24 +144,44 @@ async def channelcopy(self, interaction: discord.Interaction, channel: typing.Op description=message.content ) await logtarget.send(embed=embed) - if message.attachments !=emptyarray: + if message.attachments != emptyarray: files = message.attachments for file in files: await logtarget.send(file.url) - @app_commands.command(description='Copies the specified temp. or active channel to the archive and deletes it (admin only)') + @app_commands.command( + description='Copies the specified temp. or active channel to the archive and deletes it (admin only)' + ) @app_commands.describe( channel='Which channel do you want to delete?', ) - @app_commands.checks.has_any_role('Discord Admins', 'Liquipedia Employee', 'Administrator') + @app_commands.checks.has_any_role( + 'Discord Admins', + 'Liquipedia Employee', + 'Administrator' + ) @app_commands.guild_only() - async def channelkill(self, interaction: discord.Interaction, channel: typing.Optional[discord.TextChannel]): + async def channelkill( + self, + interaction: discord.Interaction, + channel: typing.Optional[discord.TextChannel] + ): if channel is None: channel = interaction.channel if channel is None or not channel.name.startswith('temp_'): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='Invalid channel')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='Invalid channel' + ) + ) else: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description='Messages have been archived')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description='Messages have been archived' + ) + ) emptyarray = [] logtarget = self.bot.get_channel(config.logtarget) async for message in channel.history(limit=10000, oldest_first='true'): diff --git a/ftsbot/cogs/presence.py b/ftsbot/cogs/presence.py index c1f6369..1611563 100644 --- a/ftsbot/cogs/presence.py +++ b/ftsbot/cogs/presence.py @@ -8,11 +8,19 @@ from discord.ext import commands from ftsbot import data -class presence(commands.Cog): - def __init__(self, bot): + +class presence( + commands.Cog +): + def __init__( + self, + bot + ): self.bot = bot @commands.Cog.listener() - async def on_ready(self): + async def on_ready( + self + ): game = discord.Game(name='Liquipedia', url=data.wikibaseurl, type=1) await self.bot.change_presence(activity=game) diff --git a/ftsbot/cogs/rolecommands.py b/ftsbot/cogs/rolecommands.py index cef609e..536af52 100644 --- a/ftsbot/cogs/rolecommands.py +++ b/ftsbot/cogs/rolecommands.py @@ -10,20 +10,46 @@ from ftsbot import data from ftsbot.functions import autocomplete, rolefunctions -class rolecommands(commands.Cog): - def __init__(self, bot): + +class rolecommands( + commands.Cog +): + def __init__( + self, + bot + ): self.bot = bot - @app_commands.command(description='Get your Discord ID') - async def discordid(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ffff), description='User "' + interaction.user.name + '" has ID "' + str(interaction.user.id) + '"')) + @app_commands.command( + description='Get your Discord ID' + ) + async def discordid( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ffff), + description='User "' + interaction.user.name + '" has ID "' + str(interaction.user.id) + '"' + ) + ) - @app_commands.command(description='Get your wiki roles') + @app_commands.command( + description='Get your wiki roles' + ) @app_commands.guild_only() - async def wikiroles(self, interaction: discord.Interaction): + async def wikiroles( + self, + interaction: discord.Interaction + ): apidata = rolefunctions.wikiroles(interaction.user.id) - if apidata == False: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='**Error**: Could not find user with ID "' + str(interaction.user.id) + '" on wiki')) + if apidata is False: + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='**Error**: Could not find user with ID "' + str(interaction.user.id) + '" on wiki' + ) + ) else: wikigroups = apidata[0] silverplus = apidata[1] @@ -40,40 +66,81 @@ async def wikiroles(self, interaction: discord.Interaction): role = discord.utils.get(interaction.guild.roles, name='Silver Plus') if role is not None: await interaction.user.add_roles(role) - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description='**Success**: Wiki Roles added to "' + interaction.user.name + '"')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description='**Success**: Wiki Roles added to "' + interaction.user.name + '"' + ) + ) - @app_commands.command(description='Add a role to yourself') + @app_commands.command( + description='Add a role to yourself' + ) @app_commands.describe( role='Which role do you want to add?', ) @app_commands.guild_only() - @app_commands.autocomplete(role=autocomplete.roles) - async def addrole(self, interaction: discord.Interaction, role: str): - if not role in data.botroles: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='**Error**: Can\'t add that role to "' + interaction.user.name + '"')) + @app_commands.autocomplete( + role=autocomplete.roles + ) + async def addrole( + self, + interaction: discord.Interaction, + role: str + ): + if role not in data.botroles: + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='**Error**: Can\'t add that role to "' + interaction.user.name + '"' + ) + ) else: roleobj = discord.utils.get(interaction.guild.roles, name=role) if roleobj is not None: try: await interaction.user.add_roles(roleobj) - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description='**Success**: Role "' + roleobj.name + '" added to "' + interaction.user.name + '"')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description='**Success**: Role "' + roleobj.name + '" added to "' + interaction.user.name + '"' + ) + ) except discord.Forbidden: pass - @app_commands.command(description='Remove a role from yourself') + @app_commands.command( + description='Remove a role from yourself' + ) @app_commands.describe( role='Which role do you want to remove?', ) @app_commands.guild_only() - @app_commands.autocomplete(role=autocomplete.roles) - async def removerole(self, interaction: discord.Interaction, role: str): - if not role in data.botroles: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='**Error**: Can\'t remove that role from "' + interaction.user.name + '"')) + @app_commands.autocomplete( + role=autocomplete.roles + ) + async def removerole( + self, + interaction: discord.Interaction, + role: str + ): + if role not in data.botroles: + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='**Error**: Can\'t remove that role from "' + interaction.user.name + '"' + ) + ) else: roleobj = discord.utils.get(interaction.guild.roles, name=role) if roleobj is not None: try: await interaction.user.remove_roles(roleobj) - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description='**Success**: Role "' + roleobj.name + '" removed from "' + interaction.user.name + '"')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description='**Success**: Role "' + roleobj.name + '" removed from "' + interaction.user.name + '"' + ) + ) except discord.Forbidden: pass diff --git a/ftsbot/cogs/textcommands.py b/ftsbot/cogs/textcommands.py index 65d813f..c5fb8ea 100644 --- a/ftsbot/cogs/textcommands.py +++ b/ftsbot/cogs/textcommands.py @@ -12,184 +12,474 @@ import random import typing -class textcommands(commands.Cog): - def __init__(self, bot): + +class textcommands( + commands.Cog +): + def __init__( + self, + bot + ): self.bot = bot - @app_commands.command(description='Author information') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def author(self, interaction: discord.Interaction): + @app_commands.command( + description='Author information' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def author( + self, + nteraction: discord.Interaction + ): await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x663399), description='FO-BoT was coded by **FO-nTTaX**')) @author.error - async def on_author_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_author_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='On shady betting sites') - async def betting(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ffff), description='[On shady betting sites](https://liquipedia.net/commons/User:FO-nTTaX/Betting)')) + @app_commands.command( + description='On shady betting sites' + ) + async def betting( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ffff), + description='[On shady betting sites](https://liquipedia.net/commons/User:FO-nTTaX/Betting)' + ) + ) - @app_commands.command(description='Blame someone') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def blame(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x663399), description='**#blamesalle**')) + @app_commands.command( + description='Blame someone' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def blame( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x663399), + description='**#blamesalle**' + ) + ) @blame.error - async def on_blame_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_blame_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='Dance') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def dance(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x663399), description='**EVERYBODY DANCE \\\\Ü/**\n*dances :D\\\\-<*\n*dances :D|-<*\n*dances :D/-<*')) + @app_commands.command( + description='Dance' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def dance( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x663399), + description='**EVERYBODY DANCE \\\\Ü/**\n*dances :D\\\\-<*\n*dances :D|-<*\n*dances :D/-<*' + ) + ) @dance.error - async def on_dance_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_dance_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='Roll a dice') + @app_commands.command( + description='Roll a die' + ) @app_commands.describe( sides='How many sides (default 6)?', amount='How many dice (default 1)?', ) - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def dice(self, interaction: discord.Interaction, sides: typing.Optional[int]=6, amount: typing.Optional[int]=1): + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def dice( + self, + interaction: discord.Interaction, + sides: typing.Optional[int] = 6, + amount: typing.Optional[int] = 1 + ): if sides < 2: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='A die needs to have a least 2 sides')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='A die needs to have a least 2 sides' + ) + ) elif amount < 1: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='You need to roll at least one die')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='You need to roll at least one die' + ) + ) result = '' if amount == 1: result = 'Your ' + str(sides) + '-sided die threw a ' + str(random.randrange(1, sides + 1, 1)) + '.' else: rolls = [random.randrange(1, sides + 1, 1) for _ in range(amount)] - result = 'Your ' + str(amount) + ' ' + str(sides) + '-sided dice threw ' + str(rolls) + ' for a total of ' + str(sum(rolls)) + '.' - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x663399), description=result)) + result = ( + 'Your ' + + str(amount) + + ' ' + + str(sides) + + '-sided dice threw ' + + str(rolls) + + ' for a total of ' + + str(sum(rolls)) + + '.' + ) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x663399), + description=result + ) + ) @dice.error - async def on_dice_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_dice_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='Links to guides') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def guides(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ffff), description='**Liquipedia-Guides**: https://liquipedia.net/starcraft2/User:FO-BoT#Guides')) + @app_commands.command( + description='Links to guides' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def guides( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ffff), + description='**Liquipedia-Guides**: https://liquipedia.net/starcraft2/User:FO-BoT#Guides' + ) + ) @guides.error - async def on_guides_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_guides_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='\\Ü/ HYPE \\Ü/') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def hype(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x663399), description='**\\\\Ü/ HYPE \\\\Ü/**')) + @app_commands.command( + description='\\Ü/ HYPE \\Ü/' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def hype( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x663399), + description='**\\\\Ü/ HYPE \\\\Ü/**' + ) + ) await interaction.response.send_message('https://i.imgur.com/xmdBFq9.mp4') @hype.error - async def on_hype_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_hype_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='Tell people to just ask!') - async def justask(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ffff), description='If you need help with something or just have a question, please post the question in the channel for the relevant wiki.' + - ' Asking if someone can help only costs you extra time, and you usually don\'t even need an admin!')) + @app_commands.command( + description='Tell people to just ask!' + ) + async def justask( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ffff), + description=( + 'If you need help with something or just have a question, please post the question in the channel ' + + 'for the relevant wiki.' + + ' Asking if someone can help only costs you extra time, and you usually don\'t even need an admin!' + ) + ) + ) - @app_commands.command(description='Lickypiddy!') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def lickypiddy(self, interaction: discord.Interaction): + @app_commands.command( + description='Lickypiddy!' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def lickypiddy( + self, + interaction: discord.Interaction + ): lickypiddywiki = 'commons' if isinstance(interaction.channel, discord.channel.TextChannel) and interaction.channel.name in data.wikis: lickypiddywiki = interaction.channel.name else: lickypiddywiki = 'commons' - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x663399), description='[\\\\Ü/ All glory Lickypiddy \\\\Ü/](https://liquipedia.net/' + lickypiddywiki + '/Special:Lickypiddy)')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x663399), + description='[\\\\Ü/ All glory Lickypiddy \\\\Ü/](https://liquipedia.net/' + lickypiddywiki + '/Special:Lickypiddy)' + ) + ) @lickypiddy.error - async def on_lickypiddy_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_lickypiddy_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='Tell a lie') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def lie(self, interaction: discord.Interaction): + @app_commands.command( + description='Tell a lie' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def lie( + self, + interaction: discord.Interaction + ): i = random.randrange(0, len(data.lies), 1) response = data.lies[i] if response.startswith('http'): await interaction.response.send_message(response) else: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x663399), description=response)) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x663399), + description=response + ) + ) @lie.error - async def on_lie_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_lie_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='Liquipedia!') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def liquipedia(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ffff), description='**Liquipedia** is awesome!')) + @app_commands.command( + description='Liquipedia!' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def liquipedia( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ffff), + description='**Liquipedia** is awesome!' + ) + ) @liquipedia.error - async def on_liquipedia_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_liquipedia_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='Link the notability guidelines!') + @app_commands.command( + description='Link the notability guidelines!' + ) @app_commands.describe( wiki='Which wiki do you want the notability guidelines for?', ) - @app_commands.autocomplete(wiki=autocomplete.wiki) - async def notability(self, interaction: discord.Interaction, wiki: typing.Optional[str]): + @app_commands.autocomplete( + wiki=autocomplete.wiki + ) + async def notability( + self, + interaction: discord.Interaction, + wiki: typing.Optional[str] + ): usewiki = None if wiki in data.wikis: usewiki = wiki elif isinstance(interaction.channel, discord.channel.TextChannel) and interaction.channel.name in data.wikis: usewiki = interaction.channel.name if usewiki is not None: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description='[Notability Guidelines](https://liquipedia.net/' + usewiki + '/Liquipedia:Notability_Guidelines)')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description='[Notability Guidelines](https://liquipedia.net/' + usewiki + '/Liquipedia:Notability_Guidelines)' + ) + ) else: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='No wiki specified')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='No wiki specified' + ) + ) - @app_commands.command(description='Edit Statistics') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def ranking(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ffff), description='**Liquipedia ranking**: https://liquipedia.net/statistics/?view=editcount&wikilist=all')) + @app_commands.command( + description='Edit Statistics' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def ranking( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ffff), + description='**Liquipedia ranking**: https://liquipedia.net/statistics/?view=editcount&wikilist=all' + ) + ) @ranking.error - async def on_ranking_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_ranking_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) - @app_commands.command(description='Send a link to the request form') - async def request(self, interaction: discord.Interaction): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ffff), description='[Liquipedia Request Form](https://forms.gle/1zcZHkKe6udPNv2v6)')) + @app_commands.command( + description='Send a link to the request form' + ) + async def request( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ffff), + description='[Liquipedia Request Form](https://forms.gle/1zcZHkKe6udPNv2v6)' + ) + ) - @app_commands.command(description='Think very hard') - @app_commands.checks.cooldown(1, 300, key=lambda i: (i.guild_id, i.user.id)) - async def thinking(self, interaction: discord.Interaction): + @app_commands.command( + description='Think very hard' + ) + @app_commands.checks.cooldown( + 1, + 300, + key=lambda i: (i.guild_id, i.user.id) + ) + async def thinking( + self, + interaction: discord.Interaction + ): await interaction.response.send_message('https://files.catbox.moe/o8tify.gif') - @app_commands.command(description='Troll') + @app_commands.command( + description='Troll' + ) @app_commands.describe( channel='Which channel do you want to troll?', message='What do you want to send?', ) - @app_commands.guilds(discord.Object(id=config.commandserver)) - async def troll(self, interaction: discord.Interaction, channel: str, message: str): + @app_commands.guilds( + discord.Object(id=config.commandserver) + ) + async def troll( + self, + interaction: discord.Interaction, + channel: str, + message: str + ): targetchannel = discord.utils.get(discord.utils.get(self.bot.guilds, id=config.runserver).channels, name=channel) if targetchannel is None or not isinstance(targetchannel, discord.channel.TextChannel): - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='**Error**: Can only send messages to existing text channels')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='**Error**: Can only send messages to existing text channels' + ) + ) else: sent_message = await targetchannel.send(message) - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description='**Channel**: ' + targetchannel.mention + '\n**Link**: ' + sent_message.jump_url + '\n**Message**: ' + message)) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description=( + '**Channel**: ' + targetchannel.mention + + '\n**Link**: ' + sent_message.jump_url + + '\n**Message**: ' + message + ) + ) + ) @thinking.error - async def on_thinking_error(self, interaction: discord.Interaction, error: app_commands.AppCommandError): + async def on_thinking_error( + self, + interaction: discord.Interaction, + error: app_commands.AppCommandError + ): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True) diff --git a/ftsbot/cogs/wikicommands.py b/ftsbot/cogs/wikicommands.py index 49a68de..b947867 100644 --- a/ftsbot/cogs/wikicommands.py +++ b/ftsbot/cogs/wikicommands.py @@ -11,16 +11,30 @@ from ftsbot.functions import autocomplete, wikifunctions import typing -class wikicommands(commands.Cog): - def __init__(self, bot): + +class wikicommands( + commands.Cog +): + def __init__( + self, + bot + ): self.bot = bot - @app_commands.command(description='See pending changes') + @app_commands.command( + description='See pending changes' + ) @app_commands.describe( wiki='Which wiki do you want the pending changes of?', ) - @app_commands.autocomplete(wiki=autocomplete.wiki) - async def pendingchanges(self, interaction: discord.Interaction, wiki: typing.Optional[str]): + @app_commands.autocomplete( + wiki=autocomplete.wiki + ) + async def pendingchanges( + self, + interaction: discord.Interaction, + wiki: typing.Optional[str] + ): usewiki = None if wiki in data.wikis: usewiki = wiki @@ -28,16 +42,34 @@ async def pendingchanges(self, interaction: discord.Interaction, wiki: typing.Op usewiki = interaction.channel.name if usewiki is not None: result = wikifunctions.pendingchanges(usewiki) - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description=result)) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description=result + ) + ) else: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='There seems to be no wiki with such a url!')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='There seems to be no wiki with such a url!' + ) + ) - @app_commands.command(description='See unreviewed pages') + @app_commands.command( + description='See unreviewed pages' + ) @app_commands.describe( wiki='Which wiki do you want the unreviewed pages of?', ) - @app_commands.autocomplete(wiki=autocomplete.wiki) - async def unreviewedpages(self, interaction: discord.Interaction, wiki: typing.Optional[str]): + @app_commands.autocomplete( + wiki=autocomplete.wiki + ) + async def unreviewedpages( + self, + interaction: discord.Interaction, + wiki: typing.Optional[str] + ): usewiki = None if wiki in data.wikis: usewiki = wiki @@ -45,17 +77,36 @@ async def unreviewedpages(self, interaction: discord.Interaction, wiki: typing.O usewiki = interaction.channel.name if usewiki is not None: result = wikifunctions.unreviewedpages(usewiki) - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description=result)) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description=result + ) + ) else: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='There seems to be no wiki with such a url!')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='There seems to be no wiki with such a url!' + ) + ) - @app_commands.command(description='Search Liquipedia') + @app_commands.command( + description='Search Liquipedia' + ) @app_commands.describe( search='What do you want to search?', wiki='Which wiki do you want to search?', ) - @app_commands.autocomplete(wiki=autocomplete.wiki) - async def search(self, interaction: discord.Interaction, search: str, wiki: typing.Optional[str]): + @app_commands.autocomplete( + wiki=autocomplete.wiki + ) + async def search( + self, + interaction: discord.Interaction, + search: str, + wiki: typing.Optional[str] + ): usewiki = None if wiki in data.wikis: usewiki = wiki @@ -63,6 +114,16 @@ async def search(self, interaction: discord.Interaction, search: str, wiki: typi usewiki = interaction.channel.name if usewiki is not None: result = wikifunctions.search(usewiki, search) - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0x00ff00), description=result)) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0x00ff00), + description=result + ) + ) else: - await interaction.response.send_message(embed=discord.Embed(colour=discord.Colour(0xff0000), description='There seems to be no wiki with such a url!')) + await interaction.response.send_message( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description='There seems to be no wiki with such a url!' + ) + ) diff --git a/ftsbot/config.py b/ftsbot/config.py index 666358d..c6ca722 100644 --- a/ftsbot/config.py +++ b/ftsbot/config.py @@ -4,9 +4,9 @@ # Copyright 2016-2022 Alex Winkler # Version 4.0.1 -logtarget = 339287109988909057 # Here the channel id of the channel we want the private channel logs to be stored in -privcat = 360564294401916929 # This is the id of the "Private Channels" Category -reporttarget = 191894474094280704 # This is the id of the channel reports go to +logtarget = 339287109988909057 # Here the channel id of the channel we want the private channel logs to be stored in +privcat = 360564294401916929 # This is the id of the "Private Channels" Category +reporttarget = 191894474094280704 # This is the id of the channel reports go to commandserver = 223949725068427264 runserver = 93055209017729024 diff --git a/ftsbot/functions/autocomplete.py b/ftsbot/functions/autocomplete.py index 3c6db21..1cae10f 100644 --- a/ftsbot/functions/autocomplete.py +++ b/ftsbot/functions/autocomplete.py @@ -8,7 +8,11 @@ from discord import app_commands from ftsbot import data -async def wiki(interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]: + +async def wiki( + interaction: discord.Interaction, + current: str +) -> list[app_commands.Choice[str]]: wikis = [ wiki for wiki in data.wikis if current.lower() in wiki.lower() @@ -23,7 +27,11 @@ def sortwikis(element): for wiki in wikis ][:25] -async def roles(interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]: + +async def roles( + interaction: discord.Interaction, + current: str +) -> list[app_commands.Choice[str]]: roles = [ role for role in data.botroles if current.lower() in role.lower() diff --git a/ftsbot/functions/rolefunctions.py b/ftsbot/functions/rolefunctions.py index 113ee96..92cc28a 100644 --- a/ftsbot/functions/rolefunctions.py +++ b/ftsbot/functions/rolefunctions.py @@ -10,7 +10,10 @@ import urllib from ftsbot import data, secrets -def wikiroles(discordid): + +def wikiroles( + discordid +): url = data.wikibaseurl + 'commons/api.php?format=json&action=teamliquidintegration-discordids' payload = { 'discordid': discordid, @@ -20,4 +23,7 @@ def wikiroles(discordid): if 'error' in jsonobj: return False else: - return [jsonobj['teamliquidintegration-discordids']['groups'], jsonobj['teamliquidintegration-discordids']['silverplus']] + return [ + jsonobj['teamliquidintegration-discordids']['groups'], + jsonobj['teamliquidintegration-discordids']['silverplus'] + ] diff --git a/ftsbot/functions/wikifunctions.py b/ftsbot/functions/wikifunctions.py index 3b54217..0daefe3 100644 --- a/ftsbot/functions/wikifunctions.py +++ b/ftsbot/functions/wikifunctions.py @@ -10,9 +10,16 @@ import urllib from ftsbot import data -def pendingchanges(wiki): + +def pendingchanges( + wiki +): result = '' - url = data.wikibaseurl + wiki + '/api.php?action=query&format=json&list=oldreviewedpages&ornamespace=0|10&orlimit=500' + url = ( + data.wikibaseurl + + wiki + + '/api.php?action=query&format=json&list=oldreviewedpages&ornamespace=0|10&orlimit=500' + ) jsonobj = requests.post(url).json() results = jsonobj['query']['oldreviewedpages'] count = len(results) @@ -27,14 +34,44 @@ def pendingchanges(wiki): countstr = 'over 500' else: countstr = str(count) - result = '**[Pages with pending changes](' + data.wikibaseurl + wiki + '/Special:PendingChanges)**: (' + countstr + ' page' + plural + ' pending)' + result = ( + '**[Pages with pending changes](' + + data.wikibaseurl + + wiki + + '/Special:PendingChanges)**: (' + + countstr + + ' page' + + plural + + ' pending)' + ) for i in range(0, min(count, 5)): - result += '\n- [' + results[i]['title'] + '](' + data.wikibaseurl + wiki + '/' + urllib.parse.quote(results[i]['title'].replace(' ', '_')) + ') (diff: ' + str(results[i]['diff_size']) + ', since: ' + results[i]['pending_since'][0:10] + ')' + result += ( + '\n- [' + + results[i]['title'] + + '](' + + data.wikibaseurl + + wiki + + '/' + + urllib.parse.quote(results[i]['title'].replace(' ', '_')) + + ') (diff: ' + + str(results[i]['diff_size']) + + ', since: ' + + results[i]['pending_since'][0:10] + + ')' + ) return result -def unreviewedpages(wiki): + +def unreviewedpages( + wiki +): result = '' - url = data.wikibaseurl + wiki + '/api.php?action=query&format=json&list=unreviewedpages&urfilterredir=nonredirects&urnamespace=0|10&urlimit=500' + url = ( + data.wikibaseurl + + wiki + + '/api.php?action=query&format=json&list=unreviewedpages&urfilterredir=nonredirects' + + '&urnamespace=0|10&urlimit=500' + ) jsonobj = requests.post(url).json() results = jsonobj['query']['unreviewedpages'] count = len(results) @@ -49,12 +86,34 @@ def unreviewedpages(wiki): countstr = 'over 500' else: countstr = str(count) - result = '**[Unreviewed pages](' + data.wikibaseurl + wiki + '/Special:UnreviewedPages)**: (' + countstr + ' page' + plural + ' unreviewed)' + result = ( + '**[Unreviewed pages](' + + data.wikibaseurl + + wiki + + '/Special:UnreviewedPages)**: (' + + countstr + + ' page' + + plural + + ' unreviewed)' + ) for i in range(0, min(count, 5)): - result += '\n- [' + results[i]['title'] + '](' + data.wikibaseurl + wiki + '/' + urllib.parse.quote(results[i]['title'].replace(' ', '_')) + ')' + result += ( + '\n- [' + + results[i]['title'] + + '](' + + data.wikibaseurl + + wiki + + '/' + + urllib.parse.quote(results[i]['title'].replace(' ', '_')) + + ')' + ) return result -def search(wiki, searchstring): + +def search( + wiki, + searchstring +): result = '' url = data.wikibaseurl + wiki + '/api.php?action=query&format=json&list=search&srlimit=5&srsearch=' + searchstring jsonobj = requests.post(url).json() @@ -68,7 +127,27 @@ def search(wiki, searchstring): plural = '' else: countstr = str(count) - result = '**[Search results](' + data.wikibaseurl + wiki + '/index.php?title=Special%3ASearch&profile=default&search=' + searchstring.replace(' ', '+') + '&fulltext=Search)**: (' + countstr + ' page' + plural + ')' + result = ( + '**[Search results](' + + data.wikibaseurl + + wiki + + '/index.php?title=Special%3ASearch&profile=default&search=' + + searchstring.replace(' ', '+') + + '&fulltext=Search)**: (' + + countstr + + ' page' + + plural + + ')' + ) for i in range(0, min(count, 5)): - result += '\n- [' + results[i]['title'] + '](' + data.wikibaseurl + wiki + '/' + urllib.parse.quote(results[i]['title'].replace(' ', '_')) + ')' + result += ( + '\n- [' + + results[i]['title'] + + '](' + + data.wikibaseurl + + wiki + + '/' + + urllib.parse.quote(results[i]['title'].replace(' ', '_')) + + ')' + ) return result diff --git a/ftsbot/liquipediabot.py b/ftsbot/liquipediabot.py index bb03203..994e7af 100644 --- a/ftsbot/liquipediabot.py +++ b/ftsbot/liquipediabot.py @@ -14,8 +14,13 @@ from ftsbot.cogs.textcommands import textcommands from ftsbot.cogs.wikicommands import wikicommands -class liquipediabot(commands.Bot): - def __init__(self): + +class liquipediabot( + commands.Bot +): + def __init__( + self + ): intents = discord.Intents.default() intents.members = True intents.message_content = True @@ -23,12 +28,16 @@ def __init__(self): super().__init__(intents=intents, command_prefix='!fobot', help_command=None) - async def startup(self): + async def startup( + self + ): await self.wait_until_ready() await self.tree.sync() await self.tree.sync(guild=discord.Object(id=config.commandserver)) - async def setup_hook(self): + async def setup_hook( + self + ): await self.add_cog(antispam(self)) await self.add_cog(channelmoderation(self)) await self.add_cog(presence(self)) diff --git a/ftsbot/ui/reportform.py b/ftsbot/ui/reportform.py index 1c019ce..2bbd087 100644 --- a/ftsbot/ui/reportform.py +++ b/ftsbot/ui/reportform.py @@ -8,20 +8,50 @@ from discord import ui from ftsbot import config -class reportform(ui.Modal, title='Report message to LP Admins'): - def __init__(self, bot, message): + +class reportform( + ui.Modal, + title='Report message to LP Admins' +): + def __init__( + self, + bot, + message + ): self.bot = bot self.message = message super().__init__() - whatswrong = ui.TextInput(label='What is wrong with this message?', style=discord.TextStyle.paragraph) + whatswrong = ui.TextInput( + label='What is wrong with this message?', + style=discord.TextStyle.paragraph + ) - async def on_submit(self, interaction: discord.Interaction): - await interaction.response.send_message('Thank you for your report, it has been sent to the Liquipedia Administrators', ephemeral=True) + async def on_submit( + self, + interaction: discord.Interaction + ): + await interaction.response.send_message( + 'Thank you for your report, it has been sent to the Liquipedia Administrators', + ephemeral=True + ) reporttarget = self.bot.get_channel(config.reporttarget) - text = interaction.user.mention + '** has reported this message:**\n\n' + self.message.jump_url + ' by ' + self.message.author.mention + ' with the following content:\n\n' + self.formatquote(self.message.clean_content) + '\n\n**The following reason has been given:**\n\n' + self.formatquote(self.whatswrong.value) + text = ( + interaction.user.mention + + '** has reported this message:**\n\n' + + self.message.jump_url + + ' by ' + + self.message.author.mention + + ' with the following content:\n\n' + + self.formatquote(self.message.clean_content) + + '\n\n**The following reason has been given:**\n\n' + + self.formatquote(self.whatswrong.value) + ) await reporttarget.send(text) - def formatquote(self, message): + def formatquote( + self, + message + ): return '> ' + message.replace('\n', '\n> ') diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..851c407 --- /dev/null +++ b/tox.ini @@ -0,0 +1,6 @@ +[pycodestyle] +ignore = W191,W503,E113 +max-line-length = 120 +statistics = True +show-source = True +count = True