mirror of
https://github.com/NoiTheCat/WorldTime.git
synced 2024-11-21 22:34:36 +00:00
Update version handling; client settings
This commit is contained in:
parent
1ec20dc54d
commit
c543ac2ab3
3 changed files with 21 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
# Command handlers
|
# Command handlers
|
||||||
|
# Incoming commands are fully handled by functions defined here.
|
||||||
|
|
||||||
# Incoming messages that look like commands are passed into functions defined here.
|
from common import BotVersion
|
||||||
|
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
import discord
|
import discord
|
||||||
import pytz
|
import pytz
|
||||||
|
@ -84,16 +84,15 @@ class WtCommands:
|
||||||
|
|
||||||
async def cmd_help(self, guild: discord.Guild, channel: discord.TextChannel, author: discord.User, msgcontent: str):
|
async def cmd_help(self, guild: discord.Guild, channel: discord.TextChannel, author: discord.User, msgcontent: str):
|
||||||
# Be a little fancy.
|
# Be a little fancy.
|
||||||
versionstr = subprocess.check_output(["git", "describe", "--always"]).strip()
|
|
||||||
tzcount = self.userdb.get_unique_tz_count()
|
tzcount = self.userdb.get_unique_tz_count()
|
||||||
|
|
||||||
em = discord.Embed(
|
em = discord.Embed(
|
||||||
color=14742263,
|
color=14742263,
|
||||||
title='Help & About',
|
title='Help & About',
|
||||||
description=dedent('''
|
description=dedent('''
|
||||||
World Time, version `{0}`.
|
World Time v`{0}`
|
||||||
Serving {1} communities across {2} time zones.
|
Serving {1} communities across {2} time zones.
|
||||||
'''.format(versionstr, len(self.dclient.guilds), tzcount))
|
'''.format(BotVersion, len(self.dclient.guilds), tzcount))
|
||||||
)
|
)
|
||||||
em.set_footer(text='World Time', icon_url=self.dclient.user.avatar_url)
|
em.set_footer(text='World Time', icon_url=self.dclient.user.avatar_url)
|
||||||
em.add_field(name='Commands', value=dedent('''
|
em.add_field(name='Commands', value=dedent('''
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
import pytz
|
import pytz
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
# Bot's current version (as a string), for use in the help command
|
||||||
|
BotVersion = "1.1.2"
|
||||||
|
|
||||||
# For case-insensitive time zone lookup, map lowercase tzdata entries with
|
# For case-insensitive time zone lookup, map lowercase tzdata entries with
|
||||||
# entires with proper case. pytz is case sensitive.
|
# entires with proper case. pytz is case sensitive.
|
||||||
tzlcmap = {x.lower():x for x in pytz.common_timezones}
|
tzlcmap = {x.lower():x for x in pytz.common_timezones}
|
||||||
|
|
17
worldtime.py
17
worldtime.py
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# World Time, a Discord bot. Displays user time zones.
|
# World Time, a Discord bot. Displays user time zones.
|
||||||
# - https://github.com/Noikoio/WorldTime
|
# - https://github.com/NoiTheCat/WorldTime
|
||||||
# - https://bots.discord.pw/bots/447266583459528715
|
# - https://bots.discord.pw/bots/447266583459528715
|
||||||
|
|
||||||
# Dependencies (install via pip or other means):
|
# Dependencies (install via pip or other means):
|
||||||
|
@ -11,13 +11,24 @@
|
||||||
from discord import Game
|
from discord import Game
|
||||||
from client import WorldTime
|
from client import WorldTime
|
||||||
import settings
|
import settings
|
||||||
|
import common
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
common.logPrint("World Time", "World Time v" + common.BotVersion)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if settings.BotToken == '': raise AttributeError() # Cover both scenarios: variable doesn't exist, or variable is empty
|
# Raising AttributeError here to cover either: variable doesn't exist, or variable is empty
|
||||||
|
if settings.BotToken == '': raise AttributeError()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print("Bot token not set. Will not continue.")
|
print("Bot token not set. Will not continue.")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
client = WorldTime(activity=Game('tz.help'))
|
# Note: Cannot disable guild_subscriptions - disables user cache when used in tandem w/ fetch_offline_members
|
||||||
|
# todo: sharding options handled here: pass shard_id and shard_count parameters
|
||||||
|
client = WorldTime(
|
||||||
|
fetch_offline_members=False,
|
||||||
|
# guild_subscriptions=False,
|
||||||
|
max_messages=None,
|
||||||
|
)
|
||||||
|
|
||||||
client.run(settings.BotToken)
|
client.run(settings.BotToken)
|
||||||
|
|
Loading…
Reference in a new issue