fix displaying multiple prefixes, add option to display ?help in status (#249)

* fix displaying multiple prefixes, add option to display ?help in status
Fixes #229

Co-authored-by: 0x5c <dev@0x5c.io>
This commit is contained in:
classabbyamp 2020-09-27 16:36:39 -04:00 committed by GitHub
parent a65fd04dbd
commit 488ae6cc98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 5 deletions

View File

@ -10,8 +10,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `?worksplit` command. - `?worksplit` command.
- Maps for CQ Zones, ITU Zones, ITU Regions, and Canadian prefixes. - Maps for CQ Zones, ITU Zones, ITU Regions, and Canadian prefixes.
- Attribution for all maps. - Attribution for all maps.
- Option to append ` | ?help` to the playing status.
### Changed ### Changed
- ARRL/RAC section maps to include all current ARRL/RAC sections. - ARRL/RAC section maps to include all current ARRL/RAC sections.
### Fixed
- Issue where multiple prefixes were not handled properly.
## [2.3.2] - 2020-07-22 ## [2.3.2] - 2020-07-22

View File

@ -46,9 +46,9 @@ class QrmHelpCommand(commands.HelpCommand):
if parent: if parent:
fmt = f"{parent} {fmt}" fmt = f"{parent} {fmt}"
alias = fmt alias = fmt
return f"{opt.prefix}{alias} {command.signature}\n *Aliases:* {aliases}" return f"{opt.display_prefix}{alias} {command.signature}\n *Aliases:* {aliases}"
alias = command.name if not parent else f"{parent} {command.name}" alias = command.name if not parent else f"{parent} {command.name}"
return f"{opt.prefix}{alias} {command.signature}" return f"{opt.display_prefix}{alias} {command.signature}"
async def send_error_message(self, error): async def send_error_message(self, error):
embed = cmn.embed_factory(self.context) embed = cmn.embed_factory(self.context)
@ -60,7 +60,7 @@ class QrmHelpCommand(commands.HelpCommand):
async def send_bot_help(self, mapping): async def send_bot_help(self, mapping):
embed = cmn.embed_factory(self.context) embed = cmn.embed_factory(self.context)
embed.title = "qrm Help" embed.title = "qrm Help"
embed.description = (f"For command-specific help and usage, use `{opt.prefix}help [command name]`." embed.description = (f"For command-specific help and usage, use `{opt.display_prefix}help [command name]`."
" Many commands have shorter aliases.") " Many commands have shorter aliases.")
mapping = await mapping mapping = await mapping

11
main.py
View File

@ -193,7 +193,10 @@ async def _ensure_activity_time():
try: try:
tz = pytz.timezone(opt.status_tz) tz = pytz.timezone(opt.status_tz)
except pytz.exceptions.UnknownTimeZoneError: except pytz.exceptions.UnknownTimeZoneError:
await bot.change_presence(activity=discord.Game(name="with invalid timezones.")) status = "with invalid timezones"
if opt.show_help:
status += f" | {opt.display_prefix}help"
await bot.change_presence(activity=discord.Game(name=status))
return return
now = datetime.now(tz=tz).time() now = datetime.now(tz=tz).time()
@ -203,6 +206,8 @@ async def _ensure_activity_time():
end_time = time(hour=sts[2][0], minute=sts[2][1], tzinfo=tz) end_time = time(hour=sts[2][0], minute=sts[2][1], tzinfo=tz)
if start_time < now <= end_time: if start_time < now <= end_time:
status = sts[0] status = sts[0]
if opt.show_help:
status += f" | {opt.display_prefix}help"
await bot.change_presence(activity=discord.Game(name=status)) await bot.change_presence(activity=discord.Game(name=status))
@ -210,6 +215,8 @@ async def _ensure_activity_time():
@tasks.loop(minutes=5) @tasks.loop(minutes=5)
async def _ensure_activity_random(): async def _ensure_activity_random():
status = random.choice(opt.statuses) status = random.choice(opt.statuses)
if opt.show_help:
status += f" | {opt.display_prefix}help"
await bot.change_presence(activity=discord.Game(name=status)) await bot.change_presence(activity=discord.Game(name=status))
@ -217,6 +224,8 @@ async def _ensure_activity_random():
@tasks.loop(minutes=5) @tasks.loop(minutes=5)
async def _ensure_activity_fixed(): async def _ensure_activity_fixed():
status = opt.statuses[0] status = opt.statuses[0]
if opt.show_help:
status += f" | {opt.display_prefix}help"
await bot.change_presence(activity=discord.Game(name=status)) await bot.change_presence(activity=discord.Game(name=status))

View File

@ -15,7 +15,10 @@ Settings and options for the bot.
# The prefix for the bot (str). Define a list of stings for multiple prefixes. # The prefix for the bot (str). Define a list of stings for multiple prefixes.
# ie: `["?", "!", "pls "]` # ie: `["?", "!", "pls "]`
prefix = "?" prefix = ["? ", "?"]
# The prefix to use for display purposes (ex: status message).
display_prefix = "?"
# Whether the bot should print full stacktraces for normal exceptions: `True`, # Whether the bot should print full stacktraces for normal exceptions: `True`,
# or be nice and only print small messages: `False` (the default). # or be nice and only print small messages: `False` (the default).
@ -46,6 +49,9 @@ time_statuses = [("with lids on 3.840", (00, 00), (6, 00)),
("with lids on 7.200", (18, 00), (20, 00)), ("with lids on 7.200", (18, 00), (20, 00)),
("with lids on 3.840", (20, 00), (23, 59))] ("with lids on 3.840", (20, 00), (23, 59))]
# append " | {display_prefix}help" to the Discord playing status
show_help = False
# Emoji IDs and keywords for emoji reactions # Emoji IDs and keywords for emoji reactions
# Use the format {emoji_id (int): ("tuple", "of", "lowercase", "keywords")} # Use the format {emoji_id (int): ("tuple", "of", "lowercase", "keywords")}
msg_reacts = {} msg_reacts = {}