Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0acfa77492 | ||
|
|
ffefd08761 | ||
|
|
a61662429a | ||
|
|
57244bcbfe | ||
|
|
3fd9ff46a3 | ||
|
|
d4ad727f2a | ||
|
|
516ff7feeb |
@@ -2,8 +2,8 @@
|
|||||||
Bot command for deleting the guild's scores.
|
Bot command for deleting the guild's scores.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from nextcord import Embed
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
import nextcord
|
||||||
|
|
||||||
from highscores import highscores_data # pylint: disable=import-error
|
from highscores import highscores_data # pylint: disable=import-error
|
||||||
|
|
||||||
@@ -14,29 +14,38 @@ class DeleteScores(commands.Cog, name="Delete Scores"):
|
|||||||
Deletes this guild's scores.
|
Deletes this guild's scores.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self):
|
||||||
self.bot = bot
|
"""
|
||||||
|
Default constructor for DeleteScores class. Does nothing.
|
||||||
|
"""
|
||||||
|
|
||||||
@commands.command(name="delete-scores")
|
@nextcord.slash_command(
|
||||||
@commands.has_permissions(administrator=True)
|
description="Deletes all scores for this guild. Used for testing.",
|
||||||
async def delete_scores(self, ctx: commands.Context):
|
default_member_permissions=nextcord.Permissions(administrator=True),
|
||||||
"""A command which deletes all scores for this guild.
|
)
|
||||||
Usage:
|
async def delete_scores(self, interaction: nextcord.Interaction):
|
||||||
```
|
"""
|
||||||
?delete_scores
|
A command which deletes all scores in all tables for this guild.
|
||||||
```
|
Command limits to admins to prevent devs from usings on non-test servers.
|
||||||
"""
|
"""
|
||||||
# only allow AlwaysCompiling to use.
|
# only allow AlwaysCompiling to use.
|
||||||
# If you are a developer and want to use command, can add name to list
|
# If you are a developer and want to use command, can add name to list
|
||||||
if ctx.author.id == 206602713511886849:
|
if interaction.user.id == 206602713511886849:
|
||||||
for table in highscores_data.get_guild(ctx.guild.id).tables:
|
for table in highscores_data.get_guild(interaction.guild_id).tables:
|
||||||
for category in table.categories:
|
for category in table.categories:
|
||||||
category.clear()
|
category.clear()
|
||||||
highscores_data.save_guild_data(highscores_data.get_guild(ctx.guild.id))
|
highscores_data.save_guild_data(highscores_data.get_guild(interaction.guild_id))
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"Cleared score data for {interaction.guild.name}.", ephemeral=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
"You shouldn't be using this message.", ephemeral=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
# This function will be called when this extension is loaded.
|
||||||
# It is necessary to add these functions to the bot.
|
# It is necessary to add these functions to the bot.
|
||||||
def setup(bot: commands.Bot):
|
def setup(bot: commands.Bot):
|
||||||
"""Adds function to bot"""
|
"""Adds function to bot"""
|
||||||
bot.add_cog(DeleteScores(bot))
|
bot.add_cog(DeleteScores())
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
"""
|
|
||||||
Help command
|
|
||||||
"""
|
|
||||||
|
|
||||||
from nextcord.ext import commands
|
|
||||||
|
|
||||||
from .help_command import NewHelpCommand
|
|
||||||
|
|
||||||
|
|
||||||
class HelpCog(commands.Cog):
|
|
||||||
"""Help Command"""
|
|
||||||
|
|
||||||
def __init__(self, bot: commands.Bot):
|
|
||||||
self.bot = bot
|
|
||||||
self._original_help_command = bot.help_command
|
|
||||||
bot.help_command = NewHelpCommand()
|
|
||||||
bot.help_command.cog = self
|
|
||||||
|
|
||||||
def cog_unload(self):
|
|
||||||
self.bot.help_command = self._original_help_command
|
|
||||||
|
|
||||||
|
|
||||||
# setup functions for bot
|
|
||||||
def setup(bot: commands.Bot):
|
|
||||||
"""Adds function to bot"""
|
|
||||||
bot.add_cog(HelpCog(bot))
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
"""
|
|
||||||
Help command. Copied from discord-bot-template.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import nextcord
|
|
||||||
from nextcord.embeds import EmptyEmbed
|
|
||||||
from nextcord.ext import commands
|
|
||||||
import config # pylint: disable=import-error
|
|
||||||
|
|
||||||
|
|
||||||
class NewHelpCommand(commands.MinimalHelpCommand):
|
|
||||||
"""Custom help command override using embeds"""
|
|
||||||
|
|
||||||
COLOUR = nextcord.Colour.blurple()
|
|
||||||
|
|
||||||
def get_ending_note(self):
|
|
||||||
"""Returns note to display at the bottom"""
|
|
||||||
invoked_with = self.invoked_with
|
|
||||||
return f"Use {config.BOT_PREFIX}{invoked_with} [command] for more info on a command."
|
|
||||||
|
|
||||||
def get_command_signature(self, command: commands.core.Command):
|
|
||||||
"""Retrieves the signature portion of the help page."""
|
|
||||||
return f"{command.qualified_name} {command.signature}"
|
|
||||||
|
|
||||||
async def send_bot_help(self, mapping: dict):
|
|
||||||
"""implements bot command help page"""
|
|
||||||
embed = nextcord.Embed(title="Bot Commands", colour=self.COLOUR)
|
|
||||||
avatar = self.context.bot.user.avatar
|
|
||||||
avatar_url = avatar.url if avatar else EmptyEmbed
|
|
||||||
embed.set_author(name=self.context.bot.user.name, icon_url=avatar_url)
|
|
||||||
description = self.context.bot.description
|
|
||||||
if description:
|
|
||||||
embed.description = description
|
|
||||||
|
|
||||||
for cog, commands in mapping.items(): # pylint: disable=redefined-outer-name
|
|
||||||
name = "No Category" if cog is None else cog.qualified_name
|
|
||||||
filtered = await self.filter_commands(commands, sort=True)
|
|
||||||
if filtered:
|
|
||||||
# \u2002 = middle dot
|
|
||||||
value = "\u2002".join(f"{config.BOT_PREFIX}{c.name}" for c in filtered)
|
|
||||||
if cog and cog.description:
|
|
||||||
value = f"{cog.description}\n{value}"
|
|
||||||
embed.add_field(name=name, value=value)
|
|
||||||
|
|
||||||
embed.set_footer(text=self.get_ending_note())
|
|
||||||
await self.get_destination().send(embed=embed)
|
|
||||||
|
|
||||||
async def send_cog_help(self, cog: commands.Cog):
|
|
||||||
"""implements cog help page"""
|
|
||||||
embed = nextcord.Embed(title=f"{cog.qualified_name} Commands", colour=self.COLOUR)
|
|
||||||
if cog.description:
|
|
||||||
embed.description = cog.description
|
|
||||||
|
|
||||||
filtered = await self.filter_commands(cog.get_commands(), sort=True)
|
|
||||||
for command in filtered:
|
|
||||||
embed.add_field(
|
|
||||||
name=self.get_command_signature(command),
|
|
||||||
value=command.short_doc or "...",
|
|
||||||
inline=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
embed.set_footer(text=self.get_ending_note())
|
|
||||||
await self.get_destination().send(embed=embed)
|
|
||||||
|
|
||||||
async def send_group_help(self, group: commands.Group):
|
|
||||||
"""implements group help page and command help page"""
|
|
||||||
embed = nextcord.Embed(title=group.qualified_name, colour=self.COLOUR)
|
|
||||||
if group.help:
|
|
||||||
embed.description = group.help
|
|
||||||
|
|
||||||
if isinstance(group, commands.Group):
|
|
||||||
filtered = await self.filter_commands(group.commands, sort=True)
|
|
||||||
for command in filtered:
|
|
||||||
embed.add_field(
|
|
||||||
name=self.get_command_signature(command),
|
|
||||||
value=command.short_doc or "...",
|
|
||||||
inline=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
embed.set_footer(text=self.get_ending_note())
|
|
||||||
await self.get_destination().send(embed=embed)
|
|
||||||
|
|
||||||
# Use the same function as group help for command help
|
|
||||||
send_command_help = send_group_help # type: ignore
|
|
||||||
@@ -13,35 +13,44 @@ from utilities.utils import send_highscore_message # pylint: disable=import-err
|
|||||||
class PostHighscores(commands.Cog, name="Post Highscores"):
|
class PostHighscores(commands.Cog, name="Post Highscores"):
|
||||||
"""Posts Highscores."""
|
"""Posts Highscores."""
|
||||||
|
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot) -> None:
|
||||||
|
"""
|
||||||
|
Default constructor for PostHighscores class
|
||||||
|
|
||||||
|
Args:
|
||||||
|
bot (commands.Bot): Bot object. Required to register submission button view.
|
||||||
|
"""
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command(name="post-scores")
|
@nextcord.slash_command(
|
||||||
@commands.has_permissions(administrator=True)
|
description="Triggers post/update of highscores to registered highscore channel.",
|
||||||
async def post_highscores(self, ctx: commands.Context):
|
default_member_permissions=nextcord.Permissions(administrator=True),
|
||||||
"""
|
|
||||||
A command which posts the highscore in the designated channel.
|
|
||||||
Sends warning if no channel has been registered.
|
|
||||||
Usage:
|
|
||||||
```
|
|
||||||
?post-scores
|
|
||||||
```
|
|
||||||
"""
|
|
||||||
guild = highscores_data.get_guild(ctx.guild.id)
|
|
||||||
print(f"Printing out highscores information in channel {guild.highscore_channel}")
|
|
||||||
channel = ctx.guild.get_channel(guild.highscore_channel)
|
|
||||||
|
|
||||||
error_response = "Registered Highscores channel does not exist or was never registered. "
|
|
||||||
error_response += 'Register with "?register" command.'
|
|
||||||
assert channel is not None, await ctx.send(error_response)
|
|
||||||
|
|
||||||
if len(highscores_data.get_guild(ctx.guild.id).tables) < 1:
|
|
||||||
await channel.send(
|
|
||||||
"No tables have been created for this guild. Please create some tables."
|
|
||||||
)
|
)
|
||||||
return
|
async def post_highscore_tables(self, interaction: nextcord.Interaction) -> None:
|
||||||
|
"""
|
||||||
|
A command which posts the highscore in the registered channel.
|
||||||
|
Sends warning if no channel has been registered.
|
||||||
|
"""
|
||||||
|
guild = highscores_data.get_guild(interaction.guild_id)
|
||||||
|
print(f"Printing out highscores information in channel {guild.highscore_channel}")
|
||||||
|
channel = interaction.guild.get_channel(guild.highscore_channel)
|
||||||
|
|
||||||
for table in highscores_data.get_guild(ctx.guild.id).tables:
|
# Error checking for registered highscore channel
|
||||||
|
error_response = "Registered Highscores channel does not exist or was never registered. "
|
||||||
|
error_response += 'Use "/register" to register channels.'
|
||||||
|
assert channel is not None, await interaction.response(error_response, ephemeral=True)
|
||||||
|
|
||||||
|
# Error checking for tables existing
|
||||||
|
# TODO fill out response string once functionality created.
|
||||||
|
error_response = "No tables have been created for this guild. Please create some tables."
|
||||||
|
assert (
|
||||||
|
len(highscores_data.get_guild(interaction.guild_id).tables) > 0
|
||||||
|
), await interaction.response(error_response, ephemeral=True)
|
||||||
|
|
||||||
|
# awaiting response because posting scores takes a while
|
||||||
|
await interaction.response.defer(ephemeral=True)
|
||||||
|
|
||||||
|
for table in highscores_data.get_guild(interaction.guild_id).tables:
|
||||||
message: nextcord.Message = await send_highscore_message(channel, guild, table)
|
message: nextcord.Message = await send_highscore_message(channel, guild, table)
|
||||||
await message.edit(view=SubmissionCreateButton(self.bot))
|
await message.edit(view=SubmissionCreateButton(self.bot))
|
||||||
|
|
||||||
@@ -49,6 +58,8 @@ class PostHighscores(commands.Cog, name="Post Highscores"):
|
|||||||
# messages have been sent.
|
# messages have been sent.
|
||||||
highscores_data.save_guild_data(guild)
|
highscores_data.save_guild_data(guild)
|
||||||
|
|
||||||
|
await interaction.followup.send(f"Posted all tables to <#{channel.id}>.", ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
# This function will be called when this extension is loaded.
|
# This function will be called when this extension is loaded.
|
||||||
# It is necessary to add these functions to the bot.
|
# It is necessary to add these functions to the bot.
|
||||||
|
|||||||
@@ -35,14 +35,17 @@ class BotPresence(commands.Cog, name="Bot Presence"):
|
|||||||
async def change_presence(self):
|
async def change_presence(self):
|
||||||
"""Randomly chooses a presence and updates bot's presence."""
|
"""Randomly chooses a presence and updates bot's presence."""
|
||||||
statuses = [
|
statuses = [
|
||||||
f"?help | {len(self.bot.guilds)} servers",
|
"Now with slash commands!",
|
||||||
f"Vuln Pls. | {len(self.bot.guilds)} servers",
|
"Vuln Pls.",
|
||||||
f"All your base are belong to us. | {len(self.bot.guilds)} servers",
|
"All your base are belong to us.",
|
||||||
f"Double plus good. | {len(self.bot.guilds)} servers",
|
"Double plus good.",
|
||||||
|
"That's a lot of damage!",
|
||||||
]
|
]
|
||||||
|
|
||||||
status = random.choice(statuses)
|
status = random.choice(statuses)
|
||||||
|
|
||||||
|
status += f" | {len(self.bot.guilds)} servers"
|
||||||
|
|
||||||
await self.bot.change_presence(activity=nextcord.Game(status))
|
await self.bot.change_presence(activity=nextcord.Game(status))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
Bot command for registering various channels to the bot.
|
Bot command for registering various channels to the bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from nextcord import Embed, Interaction, Permissions, SlashOption
|
|
||||||
import nextcord
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
import nextcord
|
||||||
|
|
||||||
from highscores import highscores_data # pylint: disable=import-error
|
from highscores import highscores_data # pylint: disable=import-error
|
||||||
|
|
||||||
@@ -14,10 +12,6 @@ from highscores import highscores_data # pylint: disable=import-error
|
|||||||
class Register(commands.Cog, name="Register"):
|
class Register(commands.Cog, name="Register"):
|
||||||
"""
|
"""
|
||||||
Class holds various register commands.
|
Class holds various register commands.
|
||||||
|
|
||||||
Args:
|
|
||||||
commands.Cog: Parent class
|
|
||||||
name (str, optional): Name of Cog. Defaults to "Register".
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@@ -25,7 +19,7 @@ class Register(commands.Cog, name="Register"):
|
|||||||
Default constructor for Register class. Does nothing.
|
Default constructor for Register class. Does nothing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@nextcord.slash_command(default_member_permissions=Permissions(administrator=True))
|
@nextcord.slash_command(default_member_permissions=nextcord.Permissions(administrator=True))
|
||||||
async def register(self):
|
async def register(self):
|
||||||
"""
|
"""
|
||||||
Parent slash command, never called.
|
Parent slash command, never called.
|
||||||
@@ -35,7 +29,7 @@ class Register(commands.Cog, name="Register"):
|
|||||||
async def highscore(
|
async def highscore(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.abc.GuildChannel = SlashOption(
|
channel: nextcord.abc.GuildChannel = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -62,7 +56,7 @@ class Register(commands.Cog, name="Register"):
|
|||||||
async def submission(
|
async def submission(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.abc.GuildChannel = SlashOption(
|
channel: nextcord.abc.GuildChannel = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
@@ -89,7 +83,7 @@ class Register(commands.Cog, name="Register"):
|
|||||||
async def verify(
|
async def verify(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
channel: nextcord.abc.GuildChannel = SlashOption(
|
channel: nextcord.abc.GuildChannel = nextcord.SlashOption(
|
||||||
description="Channel to register",
|
description="Channel to register",
|
||||||
required=False,
|
required=False,
|
||||||
channel_types=[nextcord.ChannelType.text],
|
channel_types=[nextcord.ChannelType.text],
|
||||||
|
|||||||
+3
-3
@@ -6,8 +6,8 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import nextcord
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
import nextcord
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from classes.highscores_data import HighscoresData
|
from classes.highscores_data import HighscoresData
|
||||||
@@ -33,9 +33,9 @@ submission_objects: SubmissionMap = SubmissionMap()
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main function for bot."""
|
"""Main function for bot."""
|
||||||
min_python_version = (3, 7)
|
min_python_version = (3, 8)
|
||||||
if sys.version_info < min_python_version:
|
if sys.version_info < min_python_version:
|
||||||
print("ERROR: Python version must be >= 3.7")
|
print("ERROR: Python version must be >= 3.8")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Allows privledged intents for monitoring members joining, roles editing, and role assignments
|
# Allows privledged intents for monitoring members joining, roles editing, and role assignments
|
||||||
|
|||||||
Reference in New Issue
Block a user