Skip to content

Commit

Permalink
Cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko259 committed Sep 3, 2021
1 parent acb8da7 commit b739fca
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 190 deletions.
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

intents = discord.Intents.all()

bot = commands.Bot(command_prefix=config.PREFIXES, description=config.DESCRIPTION, intents=intents, help_command=None, case_insensitive=True)
bot = commands.Bot(command_prefix='/', description=config.DESCRIPTION, intents=intents, help_command=None, case_insensitive=True)

slash = SlashCommand(bot, sync_commands=True)

Expand Down
41 changes: 10 additions & 31 deletions cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@

from discord.ext import commands, tasks
from discord_slash import cog_ext, SlashContext
from helpers.message import roles, embed
from helpers.config import COGS_LOAD, GUILD_ID, BOT_CHANNEL, STAFFING_INTERVAL, DEBUG
from helpers.message import staff_roles, embed
from helpers.config import COGS_LOAD, GUILD_ID, DEBUG


class AdminCog(commands.Cog):

def __init__(self, bot):
self.bot = bot
self.reload_staffing.start()

def cog_unload(self):
self.reload_staffing.cancel()

guild_ids = [GUILD_ID]

# Hidden means it won't show up on the default help.
@cog_ext.cog_slash(name="load", guild_ids=guild_ids, description="Command which Loads a Module.")
@commands.has_any_role(*roles())
@commands.has_any_role(*staff_roles())
async def load(self, ctx: SlashContext, *, cog: str):
"""
Command which Loads a Module.
Expand All @@ -34,7 +30,7 @@ async def load(self, ctx: SlashContext, *, cog: str):
await ctx.send('**`SUCCESS`**')

@cog_ext.cog_slash(name="unload", guild_ids=guild_ids, description="Command which Unloads a Module.")
@commands.has_any_role(*roles())
@commands.has_any_role(*staff_roles())
async def unload(self, ctx: SlashContext, *, cog: str):
"""
Command which Unloads a Module.
Expand All @@ -48,7 +44,7 @@ async def unload(self, ctx: SlashContext, *, cog: str):
await ctx.send('**`SUCCESS`**')

@cog_ext.cog_slash(name="reload", guild_ids=guild_ids, description="Command which Reloads a Module.")
@commands.has_any_role(*roles())
@commands.has_any_role(*staff_roles())
async def reload(self, ctx: SlashContext, *, cog: str):
"""
Command which Reloads a Module.
Expand All @@ -62,24 +58,8 @@ async def reload(self, ctx: SlashContext, *, cog: str):
else:
await ctx.send('**`SUCCESS`**')

@tasks.loop(seconds=STAFFING_INTERVAL)
async def reload_staffing(self):
"""
Command which Reloads a Module.
"""
await self.bot.wait_until_ready()
now = datetime.datetime.now()
channel = self.bot.get_channel(int(BOT_CHANNEL))

try:
if now.weekday() == 0 and now.hour == 23 and 00 <= now.minute <= 00:
self.bot.unload_extension(COGS_LOAD["staffing"])
self.bot.load_extension(COGS_LOAD["staffing"])
except Exception as e:
await channel.send(f'**`ERROR:`** {type(e).__name__} - {e}')

@cog_ext.cog_slash(name="cogs", guild_ids=guild_ids, description="Command which sends a message with all available cogs.")
@commands.has_any_role(*roles())
@commands.has_any_role(*staff_roles())
async def cogs(self, ctx: SlashContext):
"""
Command which sends a message with all available cogs.
Expand All @@ -95,7 +75,7 @@ async def cogs(self, ctx: SlashContext):
await ctx.send(embed=msg)

@cog_ext.cog_slash(name="ping", guild_ids=guild_ids, description="Function sends pong if member has any of the admin roles.")
@commands.has_any_role(*roles())
@commands.has_any_role(*staff_roles())
async def ping(self, ctx: SlashContext):
"""
Function sends pong if member has any of the admin roles
Expand All @@ -105,19 +85,19 @@ async def ping(self, ctx: SlashContext):
await ctx.send('Pong')

@cog_ext.cog_slash(name="say", guild_ids=guild_ids, description="Bot sends a specific message sent by user.")
@commands.has_any_role(*roles())
@commands.has_any_role(*staff_roles())
async def say(self, ctx: SlashContext, *, content: str) -> None:
"""
Bot sends a specific message sent by user
:param ctx:
:param content:
:return None:
"""
msg = await ctx.send("Message is being generated", delete_after=5)
await ctx.send("Message is being generated", delete_after=5)
await ctx.send(content)

@cog_ext.cog_slash(name="delete", guild_ids=guild_ids, description="Function deletes specific amount of messages.")
@commands.has_any_role(*roles())
@commands.has_any_role(*staff_roles())
async def delete(self, ctx, *, number: int = 0):
"""
Function deletes specific amount of messages
Expand All @@ -132,7 +112,6 @@ async def delete(self, ctx, *, number: int = 0):
async for msg in ctx.channel.history(limit=number):
msg_delete.append(msg)

"""await ctx.message.channel.delete_messages(msg_delete)"""
msgs = await ctx.send("Deleting messages")
await msgs.channel.purge(limit=number)
except Exception as exception:
Expand Down
100 changes: 0 additions & 100 deletions cogs/announcement.py

This file was deleted.

34 changes: 7 additions & 27 deletions cogs/staffing.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,15 @@ async def updatestaffing(self, ctx, title):

if message.content == options[0]:
newtitle = await self._get_title(ctx)
cursor.execute(
'UPDATE staffing, positions SET staffing.title = %s, positions.title = %s WHERE staffing.title = %s and positions.title = %s',
(
newtitle,
newtitle,
title,
title
)
)
cursor.execute(f'UPDATE staffing, positions SET staffing.title = {newtitle}, positions.title = {newtitle} WHERE staffing.title = {title} and positions.title = {title}')
mydb.commit()
title = newtitle
await self._updatemessage(title)
await ctx.send(f'Title updated to - {newtitle}')
await ctx.send(f'Title updated to - {title}')

elif message.content == options[1]:
newdate = await self._get_date(ctx)
cursor.execute(
'UPDATE staffing SET date = %s WHERE title = %s',
(
newdate,
title
)
)
cursor.execute(f'UPDATE staffing SET date = {newdate} WHERE title = {title}')
mydb.commit()
await self._updatemessage(title)
formatted_date = newdate.strftime("%A %d/%m/%Y")
Expand All @@ -180,13 +166,7 @@ async def updatestaffing(self, ctx, title):
newdescription = await self._get_description(ctx)
newdescription = newdescription + "\n\nTo book a position, write `/book`, press TAB and then write the callsign.\nTo unbook a position, use `/unbook`.\n\n"

cursor.execute(
'UPDATE staffing SET description = %s WHERE title = %s',
(
newdescription,
title
)
)
cursor.execute(f'UPDATE staffing SET description = {newdescription} WHERE title = {title}')
mydb.commit()
await self._updatemessage(title)
await ctx.send(f'Event description/staffing message has been updated to:\n{newdescription}')
Expand Down Expand Up @@ -306,7 +286,7 @@ async def book(self, ctx, position):
await self._updatemessage(title[0])
await ctx.send(f"<@{usernick}> Confirmed booking for position `{position.upper()}` for event `{title[0]}`", delete_after=5)
else:
await ctx.send(f"<@{usernick}> The bot could not found the position you tried to book.")
await ctx.send(f"<@{usernick}> The bot could not find the position you tried to book.")
else:
await ctx.send(f"<@{usernick}> Please use the correct channel", delete_after=5)

Expand Down Expand Up @@ -461,8 +441,8 @@ async def _get_description(self, ctx):
:return:
"""
try:
await ctx.send('Staffing message? **FYI this command expires in 3 minutes*')
message = await self.bot.wait_for('message', timeout=180, check=lambda message: message.author == ctx.author and ctx.channel == message.channel)
await ctx.send('Staffing message? **FYI this command expires in 5 minutes*')
message = await self.bot.wait_for('message', timeout=300, check=lambda message: message.author == ctx.author and ctx.channel == message.channel)

if len(message.content) < 1:
await ctx.send('Setup cancelled. No message was provided.')
Expand Down
4 changes: 2 additions & 2 deletions cogs/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from discord.ext import commands, tasks
from discord_slash import cog_ext, SlashContext
from dotenv import load_dotenv
from helpers.message import roles
from helpers.message import staff_roles
from helpers.members import get_division_members

from helpers.config import VATSIM_MEMBER_ROLE, CHECK_MEMBERS_INTERVAL, VATSCA_MEMBER_ROLE, ROLE_REASONS, GUILD_ID, DEBUG
Expand Down Expand Up @@ -89,7 +89,7 @@ async def check_members_loop(self):
guild_ids = [GUILD_ID]

@cog_ext.cog_slash(name="checkusers", guild_ids=guild_ids, description="Refresh roles based on division membership.")
@commands.has_any_role(*roles())
@commands.has_any_role(*staff_roles())
async def user_check(self, ctx: SlashContext):
await ctx.send("Member refresh in progress")
await self.check_members(True)
Expand Down
4 changes: 2 additions & 2 deletions cogs/update_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from helpers.config import ROLES_CHANNEL, GUILD_ID, RULES_CHANNEL, DIVISION_URL
from helpers.message import embed
from helpers.message import roles
from helpers.message import staff_roles


class UpdateCountryMessage(commands.Cog):
Expand Down Expand Up @@ -45,7 +45,7 @@ def __init__(self, bot):
)
])

@commands.has_any_role(*roles())
@commands.has_any_role(*staff_roles())
async def update(self, ctx, *, message_id: str = None, option: str):
"""
Function posts updated countries message
Expand Down
16 changes: 0 additions & 16 deletions helpers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

load_dotenv('.env')

PREFIXES = [
'!', '.', '?', '#'
]

DESCRIPTION = 'This is a new VATSCA Discord Bot'
PRESENCE_TEXT = 'VATSCA Airspace'

Expand All @@ -17,7 +13,6 @@
COGS = [
'cogs.admin',
'cogs.member',
#'cogs.announcement',
'cogs.tasks',
'cogs.events',
'cogs.update_messages',
Expand All @@ -27,19 +22,12 @@
COGS_LOAD = {
'admin': 'cogs.admin',
'member': 'cogs.member',
#'announcement': 'cogs.announcement',
'check_members': 'cogs.tasks',
'events': 'cogs.events',
'update': 'cogs.update_messages',
'staffing': 'cogs.staffing'
}

ADMIN_ROLES = [
'Web',
'Discord Moderator',
'Discord Administrator',
]

STAFF_ROLES = [
'Web',
'Discord Moderator',
Expand Down Expand Up @@ -101,10 +89,6 @@
GET_EVENTS_INTERVAL = int(os.getenv('GET_EVENTS_INTERVAL', 900))
DELETE_EVENTS_INTERVAL = int(os.getenv('DELETE_EVENTS_INTERVAL'))

def prefix() -> list:
return PREFIXES


def activity() -> discord.Activity:
return discord.Activity(type=discord.ActivityType.watching, name=PRESENCE_TEXT)

Expand Down
2 changes: 1 addition & 1 deletion helpers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

from datetime import datetime, timedelta
from helpers.message import embed, event_description, get_image
from helpers.message import event_description, get_image
from helpers.config import EVENT_CALENDAR_URL, FORUM_API_TOKEN

class Event():
Expand Down
Loading

0 comments on commit b739fca

Please sign in to comment.