Explorar el Código

Reporting to output channel

root hace 3 años
padre
commit
09a0d66f9f

+ 4 - 2
bot/commands/admin.py

@@ -4,6 +4,7 @@ from discord.ext import commands
 from local_settings import WEB_SCHEME, WEB_HOST
 from query.guild_access_token import get_active_token, upsert_token
 from common.datetime import plus10min
+from common.logging import report
 
 def setup(bot: commands.Bot):
 	bot.add_cog(Admin(bot))
@@ -25,9 +26,10 @@ class Admin(commands.Cog):
 
 		if record:	# Check for active token
 			await ctx.send(f"Token {record['id']} is in use by {record['user']} until {plus10min(record['created'])}.")
-		else: 
+		else:	# No active token
 			token = secrets.token_urlsafe(40)[:40]
 			await upsert_token(self.bot.pg, ctx.guild.id, ctx.author.id, token)
 
 			await ctx.author.send(f"{WEB_SCHEME}://{WEB_HOST}/config/channel-settings/{ctx.channel.id}/{token}")	# DM token
-			await ctx.send("Your access token has been sent to you in a private DM.")
+			await ctx.send("Your access token has been sent to you in a private DM.")
+			await report(self.bot, f"`{ctx.author}` has requested a token for `{ctx.guild.name}`.")

+ 4 - 1
bot/commands/general.py

@@ -3,6 +3,7 @@ import discord
 import time
 from typing import Optional
 from query.channel import get_interact
+from common.logging import report
 
 def setup(bot: commands.Bot):
 	bot.add_cog(General(bot))
@@ -52,15 +53,17 @@ class General(commands.Cog):
 			else:
 				await ctx.send("What would you like me to say?")
 		elif channel:
-			print(channel.id)
 			if await get_interact(self.bot.pg, channel.id): # or await ctx.author.get_guild_permissions(channel.guild):
 				await channel.send(message)
+				await report(f"{ctx.author}  has sent {message} to {channel.name}")
 			else:
 				await ctx.send(f"Interactive mode for {channel} is deactivated.")
 		elif user:
 			await user.send(message)
+			await report(f"{ctx.author}  has sent {message} to {user.name}")
 		else:
 			await ctx.send(message)
+			await report(self.bot, f"`{ctx.author}`  has sent `{message}` locally.")
 
 
 	@commands.command(

+ 5 - 0
bot/common/logging.py

@@ -0,0 +1,5 @@
+from local_settings import OUTPUT_CHANNEL
+
+async def report(bot, message):
+    channel = bot.get_channel(int(OUTPUT_CHANNEL))
+    await channel.send(message)

+ 1 - 1
bot/local_settings_example.py

@@ -13,4 +13,4 @@ WEB_SCHEME = "https"
 
 DISCORD_TOKEN = ""
 COMMAND_PREFIX = "!"
-OUTPUT_CHANNEL = 
+OUTPUT_CHANNEL =

+ 4 - 3
bot/query/initialise_database.py

@@ -12,7 +12,7 @@ async def init_db(pg):
                 channel_id BIGINT UNIQUE NOT NULL, \
                 guild BIGINT REFERENCES guild (guild_id), \
                 interact BOOL DEFAULT FALSE, \
-                games BOOL DEFAULT FALSE, \
+                games BOOL DEFAULT FALSE\
             )\
         ",
         "CREATE TABLE IF NOT EXISTS \
@@ -31,7 +31,8 @@ async def init_db(pg):
         "CREATE TABLE IF NOT EXISTS \
             \"user\" (\
                 id SERIAL PRIMARY KEY, \
-                user_id BIGINT UNIQUE NOT NULL\
+                user_id BIGINT UNIQUE NOT NULL, \
+                ignore BOOL DEFAULT FALSE\
             )\
         ",
         "CREATE TABLE IF NOT EXISTS \
@@ -54,4 +55,4 @@ async def init_db(pg):
         ",
     ]
     for query in queries:
-        await pg.execute(query)
+        await pg.execute(query)