Skip to content

Commit

Permalink
enforce code style
Browse files Browse the repository at this point in the history
  • Loading branch information
FO-nTTaX committed Oct 20, 2022
1 parent 98de6ba commit 5cd3770
Show file tree
Hide file tree
Showing 14 changed files with 899 additions and 186 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
80 changes: 66 additions & 14 deletions ftsbot/cogs/antispam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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:
Expand All @@ -51,22 +90,31 @@ 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')
except discord.Forbidden:
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:
Expand All @@ -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)
131 changes: 108 additions & 23 deletions ftsbot/cogs/channelmoderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand All @@ -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'):
Expand Down
14 changes: 11 additions & 3 deletions ftsbot/cogs/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading

0 comments on commit 5cd3770

Please sign in to comment.