Merge branch 'master' of https://github.com/Phxntxm/Bonfire
This commit is contained in:
commit
ca35605f97
|
@ -114,9 +114,7 @@ class Hangman:
|
|||
"""Makes a guess towards the server's currently running hangman game"""
|
||||
game = self.games.get(ctx.message.server.id)
|
||||
if not game:
|
||||
bucket = ctx.command._buckets.get_bucket(ctx)
|
||||
bucket.is_rate_limited()
|
||||
bucket._token = bucket.rate
|
||||
ctx.command.reset_cooldown(ctx)
|
||||
await self.bot.say("There are currently no hangman games running!")
|
||||
return
|
||||
|
||||
|
@ -126,9 +124,7 @@ class Hangman:
|
|||
# And also add a message for a loss/win
|
||||
if len(guess) == 1:
|
||||
if guess in game.guessed_letters:
|
||||
bucket = ctx.command._buckets.get_bucket(ctx)
|
||||
bucket.is_rate_limited()
|
||||
bucket._tokens = bucket.rate
|
||||
ctx.command.reset_cooldown(ctx)
|
||||
await self.bot.say("That letter has already been guessed!")
|
||||
# Return here as we don't want to count this as a failure
|
||||
return
|
||||
|
|
|
@ -93,21 +93,15 @@ class Interaction:
|
|||
async def battle(self, ctx, player2: discord.Member):
|
||||
"""Challenges the mentioned user to a battle"""
|
||||
if ctx.message.author.id == player2.id:
|
||||
bucket = ctx.command._buckets.get_bucket(ctx)
|
||||
bucket.is_rate_limited()
|
||||
bucket._tokens = bucket.rate
|
||||
ctx.command.reset_cooldown(ctx)
|
||||
await self.bot.say("Why would you want to battle yourself? Suicide is not the answer")
|
||||
return
|
||||
if self.bot.user.id == player2.id:
|
||||
bucket = ctx.command._buckets.get_bucket(ctx)
|
||||
bucket.is_rate_limited()
|
||||
bucket._tokens = bucket.rate
|
||||
ctx.command.reset_cooldown(ctx)
|
||||
await self.bot.say("I always win, don't even try it.")
|
||||
return
|
||||
if self.user_battling(ctx, player2):
|
||||
bucket = ctx.command._buckets.get_bucket(ctx)
|
||||
bucket.is_rate_limited()
|
||||
bucket._tokens = bucket.rate
|
||||
ctx.command.reset_cooldown(ctx)
|
||||
await self.bot.say("You or the person you are trying to battle is already in a battle!")
|
||||
return
|
||||
|
||||
|
@ -176,39 +170,23 @@ class Interaction:
|
|||
"""Boops the mentioned person"""
|
||||
booper = ctx.message.author
|
||||
if boopee.id == booper.id:
|
||||
bucket = ctx.command._buckets.get_bucket(ctx)
|
||||
bucket.is_rate_limited()
|
||||
bucket._tokens = bucket.rate
|
||||
ctx.command.reset_cooldown(ctx)
|
||||
await self.bot.say("You can't boop yourself! Silly...")
|
||||
return
|
||||
if boopee.id == self.bot.user.id:
|
||||
bucket = ctx.command._buckets.get_bucket(ctx)
|
||||
bucket.is_rate_limited()
|
||||
bucket._tokens = bucket.rate
|
||||
ctx.command.reset_cooldown(ctx)
|
||||
await self.bot.say("Why the heck are you booping me? Get away from me >:c")
|
||||
return
|
||||
|
||||
boops = await config.get_content('boops')
|
||||
|
||||
# This is only used to print the amount of times they've booped someone
|
||||
# Set to 1 for the first time someone was booped
|
||||
amount = 1
|
||||
# Get all the booped stats for the author
|
||||
booper_boops = boops.get(ctx.message.author.id)
|
||||
# If the author does not exist in the dictionary, then he has never booped someone
|
||||
# Create a new dictionary with the amount
|
||||
if booper_boops is None:
|
||||
boops[ctx.message.author.id] = {boopee.id: 1}
|
||||
# If the booper has never booped the member provided, still add that user
|
||||
# To the dictionary with the amount of 1 to start it off
|
||||
elif booper_boops.get(boopee.id) is None:
|
||||
booper_boops[boopee.id] = 1
|
||||
boops[ctx.message.author.id] = booper_boops
|
||||
# Otherwise increment how many times they've booped that user
|
||||
else:
|
||||
amount = booper_boops.get(boopee.id) + 1
|
||||
booper_boops[boopee.id] = amount
|
||||
boops[ctx.message.author.id] = booper_boops
|
||||
# Set to default as having just booped boopee 0 times, so that we can increment that
|
||||
booper_boops = boops.get(ctx.message.author.id, {boopee.id: 0})
|
||||
# If the booper has never booped the member provided, assume 0 like above so we can increment like normal
|
||||
amount = booper_boops.get(boopee.id, 0) + 1
|
||||
booper_boops[boopee.id] = amount
|
||||
boops[ctx.message.author.id] = booper_boops
|
||||
|
||||
await config.save_content('boops', boops)
|
||||
fmt = "{0.mention} has just booped you {1.mention}! That's {2} times now!"
|
||||
|
|
|
@ -109,7 +109,7 @@ class Strawpoll:
|
|||
# Save this strawpoll in the list of running strawpolls for a server
|
||||
all_polls = await config.get_content('strawpolls')
|
||||
server_polls = all_polls.get(ctx.message.server.id) or {}
|
||||
server_polls[data['id']] = {'author': ctx.message.author.id, 'date': str(pendulum.utcnow()), 'title': title}
|
||||
server_polls[str(data['id'])] = {'author': ctx.message.author.id, 'date': str(pendulum.utcnow()), 'title': title}
|
||||
all_polls[ctx.message.server.id] = server_polls
|
||||
await config.save_content('strawpolls', all_polls)
|
||||
|
||||
|
|
|
@ -82,7 +82,8 @@ 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', 'bot_data']
|
||||
'tictactoe', 'bot_data', 'command_manage']
|
||||
|
||||
# This will be a dictionary that holds the cache object, based on the key that is saved
|
||||
cache = {}
|
||||
|
||||
|
@ -124,22 +125,28 @@ async def save_content(table: str, content):
|
|||
# Now that we've saved the new content, we should update our cache
|
||||
cached = cache.get(table)
|
||||
# While this should theoretically never happen, we just want to make sure
|
||||
if cached is None or isinstance(cached, dict) or len(cached.values) == 0:
|
||||
if cached is None:
|
||||
cache[table] = Cache(table)
|
||||
else:
|
||||
await cached.update()
|
||||
loop.create_task(cached.update())
|
||||
|
||||
|
||||
async def get_content(key: str):
|
||||
cached = cache.get(key)
|
||||
# We want to check here if the key exists in cache, and it was not created more than an hour ago
|
||||
# We also want to make sure that if what we're getting in cache has content
|
||||
# if not, lets make sure something didn't go awry, by getting from the database instead
|
||||
if cached is None or isinstance(cached, dict) or len(cached.values) == 0 or (
|
||||
pendulum.utcnow() - cached.refreshed).hours >= 1:
|
||||
# If not, lets make sure something didn't go awry, by getting from the database instead
|
||||
|
||||
# If we found this object not cached, cache it
|
||||
if cached is None:
|
||||
value = await _get_content(key)
|
||||
# If we found this object not cached, cache it
|
||||
cache[key] = value
|
||||
cache[key] = Cache(key)
|
||||
# Otherwise, check our timeout and make sure values is invalid
|
||||
# If either of these are the case, we want to updated our values, and get our current data from the database
|
||||
elif len(cached.values) == 0 or (pendulum.utcnow() - cached.refreshed).hours >= 1:
|
||||
value = await _get_content(key)
|
||||
loop.create_task(cached.update())
|
||||
# Otherwise, we have valid content in cache, use it
|
||||
else:
|
||||
value = cached.values
|
||||
return value
|
||||
|
@ -154,8 +161,8 @@ async def _get_content(key: str):
|
|||
# We should only ever get one result, so use it if it exists, otherwise return none
|
||||
try:
|
||||
cursor = await r.table(key).run(conn)
|
||||
await conn.close()
|
||||
items = list(cursor.items)[0]
|
||||
await conn.close()
|
||||
except (IndexError, r.ReqlOpFailedError):
|
||||
await conn.close()
|
||||
return {}
|
||||
|
|
Loading…
Reference in a new issue