Compare commits
No commits in common. "bf9afd97920d76d80282f63c2642ccc595e67f8c" and "943813ced0b4dca991471c1250486f1563c1d329" have entirely different histories.
bf9afd9792
...
943813ced0
2 changed files with 12 additions and 20 deletions
|
@ -36,7 +36,7 @@ else:
|
|||
|
||||
TOKEN = os.getenv("TOKEN")
|
||||
DB_FILE = os.getenv("DB_FILE") or "nomen.sqlite3"
|
||||
DEFAULT_PREFIX = os.getenv("DEFAULT_PREFIX") or ">>"
|
||||
DEFAULT_PREFIX = os.getenv("DEFAULT_PREFIX") or ">"
|
||||
|
||||
|
||||
async def get_prefix(the_bot, message: Message):
|
||||
|
@ -79,11 +79,7 @@ class Nomen(Bot):
|
|||
return prefix
|
||||
|
||||
async def set_guild_prefix(self, guild: Guild, prefix):
|
||||
await self.db.execute(
|
||||
"INSERT INTO guilds VALUES(:guild_id, :prefix) ON CONFLICT(guild_id) DO UPDATE SET prefix = :prefix",
|
||||
{"guild_id": guild.id, "prefix": prefix},
|
||||
)
|
||||
await self.db.commit()
|
||||
await self.db.execute("UPDATE guilds SET prefix = ? WHERE guild_id=?", (prefix, guild.id))
|
||||
self.prefixes[guild.id] = prefix
|
||||
|
||||
async def start(self, *args, **kwargs):
|
||||
|
|
|
@ -132,13 +132,6 @@ async def handle_triggers(ctx, message):
|
|||
db_updates = []
|
||||
|
||||
search_query = """
|
||||
WITH
|
||||
pauses AS (SELECT user_id FROM user_pauses WHERE guild_id=:guild),
|
||||
ignores AS (
|
||||
SELECT target, user_id FROM user_ignores WHERE guild_id=:guild
|
||||
UNION
|
||||
SELECT target, user_id FROM user_blocks
|
||||
)
|
||||
SELECT keyword, user_id, use_embed
|
||||
FROM ( -- Deduplicate notification recipients by user_id
|
||||
SELECT keyword, user_id, use_embed, row_number() over (partition by user_id) n
|
||||
|
@ -147,11 +140,14 @@ async def handle_triggers(ctx, message):
|
|||
WHERE likely(disabled IS NOT 1) -- Don't notify users who opted out
|
||||
AND (unlikely(notify_self IS 1) OR user_id IS NOT :author) -- Don't notify author unless wanted
|
||||
AND (unlikely(bots_notify IS 1) OR :is_bot IS NOT 1) -- Don't notify from bots unless wanted
|
||||
AND likely(:author NOT IN (SELECT target FROM ignores WHERE user_id=user_id))
|
||||
AND likely(:channel NOT IN (SELECT target FROM ignores WHERE user_id=user_id))
|
||||
AND likely(:category NOT IN (SELECT target FROM ignores WHERE user_id=user_id))
|
||||
AND likely(:parent NOT IN (SELECT target FROM ignores WHERE user_id=user_id))
|
||||
AND likely(user_id NOT IN pauses)
|
||||
AND likely(NOT EXISTS(SELECT * FROM ( -- Don't notify if...
|
||||
SELECT target FROM user_ignores -- Author or channel is ignored in this guild
|
||||
WHERE user_id=user_id AND guild_id=:guild
|
||||
UNION
|
||||
SELECT target FROM user_blocks -- Author is blocked
|
||||
WHERE user_id=user_id
|
||||
) WHERE target IN (:author, :channel, :category, :parent)))
|
||||
AND likely(NOT EXISTS(SELECT * FROM user_pauses WHERE user_id=user_id AND guild_id=:guild))
|
||||
AND guild_id=:guild AND unlikely(contains(:content, keyword, regex))
|
||||
)
|
||||
WHERE n=1
|
||||
|
@ -360,14 +356,14 @@ class Notifications(Cog):
|
|||
await ctx.bot.db.commit()
|
||||
await ctx.send(f"Paused notifications in {ctx.guild}")
|
||||
|
||||
@keyword.command(aliases=["unpause"])
|
||||
@keyword.command()
|
||||
@guild_only()
|
||||
async def resume(self, ctx):
|
||||
"""
|
||||
Resume notifications in this guild
|
||||
"""
|
||||
|
||||
params = (ctx.author.id, ctx.guild.id)
|
||||
params = (ctx.author.id, ctx.guild_id)
|
||||
if await ctx.bot.db.fetch_exists("SELECT * FROM user_pauses WHERE user_id=? AND guild_id=?", params):
|
||||
await ctx.bot.db.execute("DELETE FROM user_pauses WHERE user_id=? AND guild_id=?", params)
|
||||
await ctx.bot.db.commit()
|
||||
|
|
Loading…
Add table
Reference in a new issue