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