Prepare main branch for v2.0 release

This commit is contained in:
2022-11-09 14:10:46 +01:00
parent d76aac181b
commit fba7cd3d75
11 changed files with 103 additions and 91 deletions

View File

@@ -1,33 +1,62 @@
import discord
from discord.ext import commands
from logging import getLogger
import typing
from datetime import timedelta
from discord import User, errors, TextChannel, Forbidden
# setup logging
log = getLogger(__name__)
embed = discord.Embed()
class Admin(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
@commands.command(name='purge', hidden=True)
@commands.is_owner()
async def clear(self, ctx, amount=1):
await ctx.channel.purge(limit=amount)
log.warn(f'{ctx.message.author} cleared {amount} messages')
async def purge(self, ctx, amount=1):
""" Purge <n> messages from current channel"""
await ctx.message.delete()
await ctx.channel.purge(limit = amount)
log.warn(f'{ctx.message.author} purged {amount} messages')
@commands.command(name='purge_from', hidden=True)
@commands.is_owner()
async def purge_from(self, ctx, message_id: int):
"""Purge all messages after the given message.id"""
try:
message = await ctx.channel.fetch_message(message_id)
except errors.NotFound:
log.warn(f'{ctx.message.author} tried purging {message_id}, but id was not found.')
return
await ctx.message.delete()
await ctx.channel.purge(after=message)
log.info(f'{ctx.message.author} purged all messages after {message_id}')
return True
@commands.command(name='purge_user', hidden=True)
@commands.is_owner()
async def purge_user(self, ctx, user: User, num_minutes: typing.Optional[int] = 5):
"""Clear all messages of <user.id> in all channels within the last [n=5] minutes"""
after = ctx.message.created_at - timedelta(minutes=num_minutes)
def check(msg):
return msg.author.id == user.id
for channel in await ctx.guild.fetch_channels():
if type(channel) is TextChannel:
try:
await channel.purge(limit=10*num_minutes, check=check, after=after)
log.info(f'{ctx.message.author} purged all messages from {user.id} that were posted within the last {num_minutes}')
except Forbidden:
continue
@commands.Cog.listener()
async def on_ready(self):
log.info(f'module active')
def setup(bot):
bot.add_cog(Admin(bot))
async def setup(bot):
await bot.add_cog(Admin(bot))

View File

@@ -1,52 +0,0 @@
import discord
from discord.ext import commands
from logging import getLogger
import asyncio
# setup logging
log = getLogger(__name__)
e = discord.Embed()
class Flair(commands.Cog):
""" The Flair functionality enables the user to setup flair for their profile.
Currently, the flair-roles available are:
- gender pronouns
- willingness to join mature discussions
- whether or not they are open for DMs
"""
def __init__(self, bot):
self.bot = bot
self.msg1 = ['', '', '']
@commands.command()
async def flair(self, ctx):
msg1 = (
f'Welkom bij de flair-wizard! Gebruik onderstaande opties om verder te gaan. \n\n'
f'Druk op ✅ als je verder wil gaan met de wizard.\n'
f'Als je niet je flair opnieuw wilt instellen, druk dan op ❌.\n'
f'Gebruik ❔ als je wil weten hoe je via een tekstcommando alles kan instellen.\n\n'
)
dm = await ctx.author.send(msg1)
log.info(f'{ctx.author} started the flair wizard')
for emoji in self.msg1:
await dm.add_reaction(emoji)
@commands.Cog.listener()
async def on_ready(self):
log.info(f'module active')
def setup(bot):
bot.add_cog(Flair(bot))
# numbers_reactions = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣']

View File

@@ -44,5 +44,5 @@ class Games(commands.Cog):
log.info(f'module active')
def setup(bot):
bot.add_cog(Games(bot))
async def setup(bot):
await bot.add_cog(Games(bot))

View File

@@ -63,5 +63,5 @@ class Gif(commands.Cog):
log.info(f'module active')
def setup(bot):
bot.add_cog(Gif(bot))
async def setup(bot):
await bot.add_cog(Gif(bot))

View File

@@ -32,6 +32,6 @@ class Links(commands.Cog):
log.info(f'module active')
def setup(bot):
bot.add_cog(Links(bot))
async def setup(bot):
await bot.add_cog(Links(bot))

View File

@@ -33,5 +33,5 @@ class Misc(commands.Cog):
log.info(f'module active')
def setup(bot):
bot.add_cog(Misc(bot))
async def setup(bot):
await bot.add_cog(Misc(bot))

View File

@@ -22,5 +22,5 @@ class Moderator(commands.Cog):
log.info(f'module active')
def setup(bot):
bot.add_cog(Moderator(bot))
async def setup(bot):
await bot.add_cog(Moderator(bot))