1
0
Fork 0
mirror of synced 2024-06-02 02:34:32 +12:00

Ensured uptime is valid by making it first

This commit is contained in:
phxntxm 2016-08-31 16:19:39 -05:00
parent 2f94ed9459
commit f7bdf39845
2 changed files with 16 additions and 3 deletions

5
bot.py
View file

@ -45,6 +45,9 @@ async def on_ready():
channel_id = await config.get_content('restart_server')
channel_id = channel_id or 0
if not hasattr(bot, 'uptime'):
bot.uptime = pendulum.utcnow()
# Just in case the bot was restarted while someone was battling, clear it so they do not get stuck
await config.save_content('battling', {})
# Check if the bot was restarted, if so send a message to the channel the bot was restarted from
@ -52,8 +55,6 @@ async def on_ready():
destination = discord.utils.find(lambda m: m.id == channel_id, bot.get_all_channels())
await bot.send_message(destination, "I have just finished restarting!")
await config.save_content('restart_server', 0)
if not hasattr(bot, 'uptime'):
bot.uptime = pendulum.utcnow()
@bot.event

View file

@ -82,14 +82,24 @@ db_opts = {'host': db_host, 'db': db_name, 'port': db_port, 'user': db_user, 'pa
possible_keys = ['prefixes', 'battling', 'battle_records', 'boops', 'server_alerts', 'user_notifications',
'nsfw_channels', 'custom_permissions', 'rules', 'overwatch', 'picarto', 'twitch', 'strawpolls', 'tags',
'tictactoe']
'tictactoe', 'bot_data']
# This will be a dictionary that holds the cache object, based on the key that is saved
cache = {}
sharded_data = {}
# Populate cache with each object
for k in possible_keys:
cache[k] = Cache(k)
""" { 'shard_0': {'server_count': 146,
'member_count': 146}
}"""
def get_bot_data(key):
# This method will handle data that we'd like to get across all shards
# First get the bot's data from cache or the database
bot_data = get_content('bot_data')
def command_prefix(bot, message):
# We do not want to make a query for every message that is sent
@ -129,6 +139,8 @@ async def get_content(key: str):
cached = cache.get('key')
if cached is None:
value = await _get_content(key)
# If we found this object not cached, cache it
cache['key'] = value
else:
value = cached.values
return value