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
18
18
[LOGGING ]
19
19
webhook_url = " " # optional
20
20
webhook_avatar_url = " " # optional
21
+ runner = 123456789 # optional: sets the webhook avatar url (will be overridden by the webhook_avatar_url attribute)
21
22
level = 20
22
23
23
24
[SNEKBOX ] # optional
Original file line number Diff line number Diff line change 27
27
28
28
import discord
29
29
from discord .ext import commands , tasks
30
- from discord .utils import format_dt
30
+ from discord .utils import MISSING , format_dt
31
31
32
32
import core
33
33
34
34
35
35
class Logging (commands .Cog ):
36
36
def __init__ (self , bot : core .Bot ) -> None :
37
37
self .bot = bot
38
+
39
+ self .user : discord .User | None = MISSING # none is for a failed fetch
40
+
38
41
if url := core .CONFIG ["LOGGING" ].get ("webhook_url" ):
39
42
self .webhook = discord .Webhook .from_url (url , session = bot .session , client = bot )
40
43
else :
@@ -64,9 +67,23 @@ async def logging_loop(self) -> None:
64
67
65
68
embed = to_log .__dict__ .get ("embed" ) or discord .utils .MISSING
66
69
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
+
67
84
await self .webhook .send (
68
85
message ,
69
- username = "PythonistaBot Logging" ,
86
+ username = actor_name ,
70
87
avatar_url = core .CONFIG ["LOGGING" ].get ("webhook_avatar_url" ),
71
88
embed = embed ,
72
89
)
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class Logging(TypedDict):
20
20
webhook_url : NotRequired [str ]
21
21
webhook_avatar_url : NotRequired [str ]
22
22
level : int
23
+ runner : NotRequired [int ]
23
24
24
25
25
26
class Snekbox (TypedDict ):
You can’t perform that action at this time.
0 commit comments