Refresh cache on some important updates
This commit is contained in:
parent
a2bbe427be
commit
d031459349
5
bot.py
5
bot.py
|
@ -25,7 +25,10 @@ logging.basicConfig(level=logging.INFO, filename='bonfire.log')
|
|||
|
||||
@bot.before_invoke
|
||||
async def start_typing(ctx):
|
||||
await ctx.trigger_typing()
|
||||
try:
|
||||
await ctx.trigger_typing()
|
||||
except (discord.Forbidden, discord.HTTPException):
|
||||
pass
|
||||
|
||||
|
||||
@bot.event
|
||||
|
|
|
@ -42,6 +42,8 @@ class GuildConfiguration:
|
|||
return await converter.convert(ctx, setting)
|
||||
|
||||
async def _set_db_guild_opt(self, opt, setting, ctx):
|
||||
if opt == "prefix":
|
||||
ctx.bot.cache.update_prefix(ctx.guild, setting)
|
||||
try:
|
||||
return await ctx.bot.db.execute(f"INSERT INTO guilds (id, {opt}) VALUES ($1, $2)", ctx.guild.id, setting)
|
||||
except UniqueViolationError:
|
||||
|
@ -157,6 +159,7 @@ WHERE
|
|||
id=$2 AND
|
||||
NOT $1 = ANY(ignored_channels);
|
||||
"""
|
||||
ctx.bot.loop.create_task(ctx.cache.load_ignored())
|
||||
return await ctx.bot.db.execute(query, channel.id, ctx.guild.id)
|
||||
|
||||
async def _handle_set_ignored_members(self, ctx, setting):
|
||||
|
@ -176,6 +179,7 @@ WHERE
|
|||
id=$2 AND
|
||||
NOT $1 = ANY(ignored_members);
|
||||
"""
|
||||
ctx.bot.loop.create_task(ctx.cache.load_ignored())
|
||||
return await ctx.bot.db.execute(query, setting, ctx.guild.id)
|
||||
|
||||
async def _handle_set_rules(self, ctx, setting):
|
||||
|
|
|
@ -146,16 +146,16 @@ class Interaction:
|
|||
"SELECT custom_hugs, include_default_hugs FROM guilds WHERE id = $1",
|
||||
ctx.guild.id
|
||||
)
|
||||
custom_msgs = settings["custom_hugs"]
|
||||
default_on = settings["include_default_hugs"]
|
||||
if custom_msgs:
|
||||
if default_on or default_on is None:
|
||||
msgs = hugs + custom_msgs
|
||||
else:
|
||||
msgs = custom_msgs
|
||||
msgs = hugs
|
||||
if settings:
|
||||
custom_msgs = settings["custom_hugs"]
|
||||
default_on = settings["include_default_hugs"]
|
||||
if custom_msgs:
|
||||
if default_on or default_on is None:
|
||||
msgs += custom_msgs
|
||||
else:
|
||||
msgs = custom_msgs
|
||||
# Otherwise we simply just want to use the default, no matter what the default setting is
|
||||
else:
|
||||
msgs = hugs
|
||||
|
||||
fmt = random.SystemRandom().choice(msgs)
|
||||
await ctx.send(fmt.format(user=user.display_name))
|
||||
|
|
Loading…
Reference in a new issue