Update version handling; client settings

This commit is contained in:
Noi 2019-12-26 19:33:40 -08:00
parent 1ec20dc54d
commit c543ac2ab3
3 changed files with 21 additions and 8 deletions

View file

@ -1,7 +1,7 @@
# 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
import discord
import pytz
@ -84,16 +84,15 @@ class WtCommands:
async def cmd_help(self, guild: discord.Guild, channel: discord.TextChannel, author: discord.User, msgcontent: str):
# Be a little fancy.
versionstr = subprocess.check_output(["git", "describe", "--always"]).strip()
tzcount = self.userdb.get_unique_tz_count()
em = discord.Embed(
color=14742263,
title='Help & About',
description=dedent('''
World Time, version `{0}`.
World Time v`{0}`
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.add_field(name='Commands', value=dedent('''

View file

@ -3,6 +3,9 @@
import pytz
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
# entires with proper case. pytz is case sensitive.
tzlcmap = {x.lower():x for x in pytz.common_timezones}

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# 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
# Dependencies (install via pip or other means):
@ -11,13 +11,24 @@
from discord import Game
from client import WorldTime
import settings
import common
if __name__ == '__main__':
common.logPrint("World Time", "World Time v" + common.BotVersion)
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:
print("Bot token not set. Will not continue.")
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)