countdown-bot

A Discord bot that runs countdown games and generates analytics
git clone https://git.ashermorgan.net/countdown-bot/
Log | Files | Refs | README

helpCog.py (13972B)


      1 # Import dependencies
      2 import discord
      3 from discord.ext import commands
      4 
      5 # Import modules
      6 from .botUtilities import COLORS, CommandError
      7 
      8 
      9 
     10 class Help(commands.Cog):
     11     def __init__(self, bot):
     12         self.bot = bot
     13         self.bot.remove_command("help")
     14 
     15 
     16 
     17     @commands.Cog.listener()
     18     async def on_guild_join(self, guild):
     19         # Log status
     20         self.logger.info(f"Added to {guild} (ID {guild.id})")
     21 
     22         # Get command prefix
     23         prefix = self.bot.prefixes[0]
     24 
     25         # Create embed
     26         embed=discord.Embed(title=":rocket: Getting Started with countdown-bot", color=COLORS["embed"])
     27         embed.description = f"Thanks for adding me to your server! Here are some steps for getting started:\n"
     28         embed.description += f"**1.** View help information using the `{prefix}help` command\n"
     29         embed.description += f"**2.** Activate a new countdown channel using the `{prefix}activate` command\n"
     30         embed.description += f"**3.** Change my settings using the `{prefix}config` command\n"
     31         embed.description += f"**4.** View countdown analytics using the `{prefix}analytics` command\n"
     32 
     33         # Send embed
     34         await ctx.guild.system_channel.send(embed=embed)
     35 
     36 
     37 
     38     @commands.Cog.listener()
     39     async def on_message(self, obj):
     40         # Respond to @mentions
     41         if self.bot.user in obj.mentions:
     42             embed=discord.Embed(title="countdown-bot", description=f"Use `{(await self.bot.get_prefix(obj))[0]}help` to view help information", color=COLORS["embed"])
     43             await obj.channel.send(embed=embed)
     44 
     45 
     46 
     47     @commands.command(aliases=["h", ""])
     48     async def help(self, ctx, command=None):
     49         """
     50         Shows help information
     51         """
     52 
     53         # Initialize help information
     54         prefixes = await self.bot.get_prefix(ctx)
     55         help_text = {
     56             "prefixes":
     57                 f"`{'`, `'.join(prefixes)}`",
     58             "utility-commands":
     59                 "**-** `activate`: Turns a channel into a countdown\n" \
     60                 "**-** `config`: Shows and modifies bot and countdown settings\n" \
     61                 "**-** `deactivate`: Deactivates a countdown channel\n" \
     62                 "**-** `help`, `h`: Shows help information\n" \
     63                 "**-** `ping`: Pings the bot\n" \
     64                 "**-** `reload`: Reloads the countdown cache\n",
     65             "analytics-commands":
     66                 "**-** `analytics`, `a`: Shows all countdown analytics\n" \
     67                 "**-** `contributors`, `c`: Shows information about countdown contributors\n" \
     68                 "**-** `eta`, `e`: Shows information about the estimated completion date\n" \
     69                 "**-** `heatmap`: Shows a heatmap of when messages are sent\n" \
     70                 "**-** `leaderboard`, `l`: Shows the countdown leaderboard\n" \
     71                 "**-** `progress`, `p`: Shows information about countdown progress\n" \
     72                 "**-** `speed`, `s`: Shows information about countdown speed\n",
     73             "behavior":
     74                 "**-** Reacts with :no_entry: when a user counts out of turn\n" \
     75                 "**-** Reacts with :x: when a user counts incorrectly\n" \
     76                 "**-** Ignores messages that don't start with a (positive) number\n" \
     77                 "**-** Pins numbers every 2% if the countdown started at 500 or higher\n",
     78             "getting-started":
     79                 f"**1.** View help information using the `{prefixes[0]}help` command\n" \
     80                 f"**2.** Activate a new countdown channel using the `{prefixes[0]}activate` command\n" \
     81                 f"**3.** Change my settings using the `{prefixes[0]}config` command\n" \
     82                 f"**4.** View countdown analytics using the `{prefixes[0]}analytics` command\n",
     83             "troubleshooting":
     84                 f"**1.** Run `{prefixes[0]}ping` to make sure that I'm online\n" \
     85                 f"**2.** If I reacted incorrectly to a message, remove my incorrect reaction(s)\n" \
     86                 f"**3.** Run `{prefixes[0]}reload` in the countdown channel\n",
     87             "activate":
     88                 "**Name:** activate\n" \
     89                 "**Description:** Turns a channel into a countdown\n" \
     90                 f"**Usage:** `{prefixes[0]}activate`\n" \
     91                 "**Aliases:** none\n" \
     92                 "**Arguments:** none\n" \
     93                 "**Examples:**\n" \
     94                 f"**-** `{prefixes[0]}activate`\n" \
     95                 "**Notes:** Users must have admin permissions to turn a channel into a countdown\n",
     96             "analytics":
     97                 "**Name:** analytics\n" \
     98                 "**Description:** Shows all countdown analytics\n" \
     99                 f"**Usage:** `{prefixes[0]}analytics|a`\n" \
    100                 "**Aliases:** `a`\n" \
    101                 "**Arguments: none**\n" \
    102                 "**Examples:**\n" \
    103                 f"**-** `{prefixes[0]}analytics`\n" \
    104                 "**Notes:** none\n",
    105             "config":
    106                 "**Name:** config\n" \
    107                 "**Description:** Shows and modifies countdown settings\n" \
    108                 f"**Usage:** `{prefixes[0]}config [<key> <value>...]`\n" \
    109                 "**Aliases:** none\n" \
    110                 "**Arguments:**\n" \
    111                 "**-** `<key>`: The name of the setting to modify. If no key is supplied, all settings will be shown\n" \
    112                 "**-** `<value>`: The new value(s) for the setting\n" \
    113                 "**Available Settings:**\n" \
    114                 "**-** `prefix`, `prefixes`: The prefix(es) for the bot\n" \
    115                 "**-** `tz`, `timezone`: The UTC offset in hours\n" \
    116                 "**-** `react`: The reactions for a certain number\n" \
    117                 "**Examples:**\n" \
    118                 f"**-** `{prefixes[0]}config`\n" \
    119                 f"**-** `{prefixes[0]}config prefixes prefix1 prefix2 prefix3`\n" \
    120                 f"**-** `{prefixes[0]}config timezone -1.5`\n" \
    121                 f"**-** `{prefixes[0]}config react 0 :partying_face: :smile:`\n" \
    122                 "**Notes:** Users must have admin permissions to modify settings\n",
    123             "contributors":
    124                 "**Name:** contributors\n" \
    125                 "**Description:** Shows information about countdown contributors\n" \
    126                 f"**Usage:** `{prefixes[0]}contributors|c [history|h]`\n" \
    127                 "**Aliases:** `c`\n" \
    128                 "**Arguments:**\n" \
    129                 "**-** `history`, `h`: Shows historical data about countdown contributors\n" \
    130                 "**Examples:**\n" \
    131                 f"**-** `{prefixes[0]}contributors`\n" \
    132                 f"**-** `{prefixes[0]}contributors history`\n" \
    133                 "**Notes:** The contributors embed will only show the top 20 contributors\n",
    134             "deactivate":
    135                 "**Name:** deactivate\n" \
    136                 "**Description:** Deactivates a countdown channel\n" \
    137                 f"**Usage:** `{prefixes[0]}deactivate`\n" \
    138                 "**Aliases:** none\n" \
    139                 "**Arguments:** none\n" \
    140                 "**Examples:**\n" \
    141                 f"**-** `{prefixes[0]}deactivate`\n" \
    142                 "**Notes:** Users must have admin permissions to deactivate a countdown channel\n",
    143             "eta":
    144                 "**Name:** eta\n" \
    145                 "**Description:** Shows information about the estimated completion date\n" \
    146                 f"**Usage:** `{prefixes[0]}eta|e`\n" \
    147                 "**Aliases:** `e`\n" \
    148                 "**Arguments:** none\n" \
    149                 "**Examples:**\n" \
    150                 f"**-** `{prefixes[0]}eta`\n" \
    151                 "**Notes:** none\n",
    152             "heatmap":
    153                 "**Name:** heatmap\n" \
    154                 "**Description:** Shows a heatmap of when countdown messages are sent\n" \
    155                 f"**Usage:** `{prefixes[0]}heatmap [<user>]`\n" \
    156                 "**Aliases:** none\n" \
    157                 "**Arguments:**\n" \
    158                 "**-** `<user>`: The user to view heatmap information about. If no value is supplied, the general heatmap will be shown\n" \
    159                 "**Examples:**\n" \
    160                 f"**-** `{prefixes[0]}heatmap`\n" \
    161                 f"**-** `{prefixes[0]}heatmap @Alice`\n" \
    162                 "**Notes:** none\n",
    163             "help":
    164                 "**Name:** help\n" \
    165                 "**Description:** Shows help information\n" \
    166                 f"**Usage:** `{prefixes[0]}help|h [<command>]`\n" \
    167                 "**Aliases:** `h`\n" \
    168                 "**Arguments:**\n" \
    169                 "**-** `<command>`: The command to view help information about. If no value is supplied, general help information will be shown\n" \
    170                 "**Examples:**\n" \
    171                 f"**-** `{prefixes[0]}help`\n" \
    172                 f"**-** `{prefixes[0]}help config`\n" \
    173                 "**Notes:** none\n",
    174             "leaderboard":
    175                 "**Name:** leaderboard\n" \
    176                 "**Description:** Shows the countdown leaderboard\n" \
    177                 f"**Usage:** `{prefixes[0]}leaderboard|l [<user>]`\n" \
    178                 "**Aliases:** `l`\n" \
    179                 "**Arguments:**\n" \
    180                 "**-** `<user>`: The user to view leaderboard information about. If no value is supplied, the whole leaderboard will be shown\n" \
    181                 "**Examples:**\n" \
    182                 f"**-** `{prefixes[0]}leaderboard`\n" \
    183                 f"**-** `{prefixes[0]}leaderboard @Alice`\n" \
    184                 "**Notes:** The leaderboard embed will only show the top 20 contributors\n",
    185             "ping":
    186                 "**Name:** ping\n" \
    187                 "**Description:** Pings the bot\n" \
    188                 f"**Usage:** `{prefixes[0]}ping`\n" \
    189                 "**Aliases:** none\n" \
    190                 "**Arguments:** none\n" \
    191                 "**Examples:**\n" \
    192                 f"**-** `{prefixes[0]}ping`\n" \
    193                 "**Notes:** none\n",
    194             "progress":
    195                 "**Name:** progress\n" \
    196                 "**Description:** Shows information about countdown progress\n" \
    197                 f"**Usage:** `{prefixes[0]}progress|p`\n" \
    198                 "**Aliases:** `p`\n" \
    199                 "**Arguments:** none\n" \
    200                 "**Examples:**\n" \
    201                 f"**-** `{prefixes[0]}progress`\n" \
    202                 "**Notes:** none\n",
    203             "reload":
    204                 "**Name:** reload\n" \
    205                 "**Description:** Reloads the countdown cache\n" \
    206                 f"**Usage:** `{prefixes[0]}reload`\n" \
    207                 "**Aliases:** none\n" \
    208                 "**Arguments:** none\n" \
    209                 "**Examples:**\n" \
    210                 f"**-** `{prefixes[0]}reload`\n" \
    211                 "**Notes:** This command must be used in a countdown channel\n",
    212             "speed":
    213                 "**Name:** speed\n" \
    214                 "**Description:** Shows information about countdown speed\n" \
    215                 f"**Usage:** `{prefixes[0]}speed|s [<period>]`\n" \
    216                 "**Aliases:** `s`\n" \
    217                 "**Arguments:**\n" \
    218                 "**-** `<period>`: The size of the period in hours (the default is 24 hours)\n" \
    219                 "**Examples:**\n" \
    220                 f"**-** `{prefixes[0]}speed`\n" \
    221                 f"**-** `{prefixes[0]}speed 48`\n" \
    222                 "**Notes:** none\n",
    223         }
    224 
    225         # Create embed
    226         embed=discord.Embed(title=":grey_question: countdown-bot Help", color=COLORS["embed"])
    227         if (command is None):
    228             embed.add_field(name="Command Prefixes :gear:", value=help_text["prefixes"], inline=False)
    229             embed.add_field(name="Utility Commands :wrench:", value=help_text["utility-commands"], inline=False)
    230             embed.add_field(name="Analytics Commands :bar_chart:", value=help_text["analytics-commands"], inline=False)
    231             embed.add_field(name="Behavior in Countdown Channels :robot:", value=help_text["behavior"], inline=False)
    232             embed.add_field(name="Getting Started :rocket:", value=help_text["getting-started"], inline=False)
    233             embed.add_field(name="Troubleshooting :screwdriver:", value=help_text["troubleshooting"], inline=False)
    234             embed.description = f"Use `{prefixes[0]}help <command>` to get more info on a command"
    235         elif (command.lower() in ["activate"]):
    236             embed.description = help_text["activate"]
    237         elif (command.lower() in ["a", "analytics"]):
    238             embed.description = help_text["analytics"]
    239         elif (command.lower() in ["config"]):
    240             embed.description = help_text["config"]
    241         elif (command.lower() in ["c", "contributors"]):
    242             embed.description = help_text["contributors"]
    243         elif (command.lower() in ["deactivate"]):
    244             embed.description = help_text["deactivate"]
    245         elif (command.lower() in ["e", "eta"]):
    246             embed.description = help_text["eta"]
    247         elif (command.lower() in ["heatmap"]):
    248             embed.description = help_text["heatmap"]
    249         elif (command.lower() in ["h", "help"]):
    250             embed.description = help_text["help"]
    251         elif (command.lower() in ["l", "leaderboard"]):
    252             embed.description = help_text["leaderboard"]
    253         elif (command.lower() in ["ping"]):
    254             embed.description = help_text["ping"]
    255         elif (command.lower() in ["p", "progress"]):
    256             embed.description = help_text["progress"]
    257         elif (command.lower() in ["reload"]):
    258             embed.description = help_text["reload"]
    259         elif (command.lower() in ["s", "speed"]):
    260             embed.description = help_text["speed"]
    261         else:
    262             raise CommandError(f"Command not found: `{command}`")
    263 
    264         # Send embed
    265         await ctx.send(embed=embed)
    266 
    267 
    268 
    269     @commands.command()
    270     async def ping(self, ctx):
    271         """
    272         Pings the bot
    273         """
    274 
    275         embed=discord.Embed(title=":ping_pong: Pong!", color=COLORS["embed"])
    276         embed.description = f"**Latency:** {round(self.bot.latency * 1000)} ms\n"
    277         await ctx.send(embed=embed)