File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ dsn = 'postgres://pythonistabot:pythonistabot@database:5432/pythonistabot' # ass
1818[LOGGING ]
1919webhook_url = " " # optional
2020webhook_avatar_url = " " # optional
21+ runner = 123456789 # optional: sets the webhook avatar url (will be overridden by the webhook_avatar_url attribute)
2122level = 20
2223
2324[SNEKBOX ] # optional
Original file line number Diff line number Diff line change 2727
2828import discord
2929from discord .ext import commands , tasks
30- from discord .utils import format_dt
30+ from discord .utils import MISSING , format_dt
3131
3232import core
3333
3434
3535class Logging (commands .Cog ):
3636 def __init__ (self , bot : core .Bot ) -> None :
3737 self .bot = bot
38+
39+ self .user : discord .User | None = MISSING # none is for a failed fetch
40+
3841 if url := core .CONFIG ["LOGGING" ].get ("webhook_url" ):
3942 self .webhook = discord .Webhook .from_url (url , session = bot .session , client = bot )
4043 else :
@@ -64,9 +67,23 @@ async def logging_loop(self) -> None:
6467
6568 embed = to_log .__dict__ .get ("embed" ) or discord .utils .MISSING
6669
70+ avatar_url : str | None = core .CONFIG ["LOGGING" ].get ("webhook_avatar_url" )
71+ actor_name = "PythonistaBot Logging"
72+
73+ if not avatar_url and self .user is not None and "runner" in core .CONFIG ["LOGGING" ]:
74+ runner_id : int = core .CONFIG ["LOGGING" ]["runner" ]
75+ try :
76+ user = self .user or self .bot .get_or_fetch_user (runner_id )
77+ except :
78+ self .user = user = None # This will tell us not to attempt again.
79+
80+ if user :
81+ avatar_url = user .display_avatar .url
82+ actor_name = f"Logging: Dev: { user .display_name } "
83+
6784 await self .webhook .send (
6885 message ,
69- username = "PythonistaBot Logging" ,
86+ username = actor_name ,
7087 avatar_url = core .CONFIG ["LOGGING" ].get ("webhook_avatar_url" ),
7188 embed = embed ,
7289 )
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class Logging(TypedDict):
2020 webhook_url : NotRequired [str ]
2121 webhook_avatar_url : NotRequired [str ]
2222 level : int
23+ runner : NotRequired [int ]
2324
2425
2526class Snekbox (TypedDict ):
You can’t perform that action at this time.
0 commit comments