|
@@ -35,19 +35,30 @@ class DiscordBot(rollbot.Rollbot[discord.Message]):
|
|
|
if cfg is None:
|
|
|
return None
|
|
|
return cfg
|
|
|
-
|
|
|
- async def on_command(self, raw: discord.Message, message: rollbot.Message, command: str):
|
|
|
+
|
|
|
+ async def on_command(
|
|
|
+ self, raw: discord.Message, message: rollbot.Message, command: str
|
|
|
+ ):
|
|
|
async with raw.channel.typing():
|
|
|
return await super().on_command(raw, message, command)
|
|
|
|
|
|
- async def on_reaction_add(self, reaction: discord.Reaction, user: discord.Member | discord.User):
|
|
|
+ async def on_reaction_add(
|
|
|
+ self, reaction: discord.Reaction, user: discord.Member | discord.User
|
|
|
+ ):
|
|
|
sender_id = getattr(reaction.message.author, "id", None)
|
|
|
- if str(sender_id) not in secrets["discord"].get("wants_react_notifs", []) or user.id == sender_id:
|
|
|
+ if (
|
|
|
+ str(sender_id) not in secrets["discord"].get("wants_react_notifs", [])
|
|
|
+ or user.id == sender_id
|
|
|
+ ):
|
|
|
return
|
|
|
channel_name = getattr(reaction.message.channel, "name", "UNKNOWN CHANNEL")
|
|
|
content = reaction.message.content
|
|
|
- content = (content[:17] + '...') if len(content) > 17 else content
|
|
|
- react_name = reaction.emoji if isinstance(reaction.emoji, str) else f":{reaction.emoji.name}:"
|
|
|
+ content = (content[:17] + "...") if len(content) > 17 else content
|
|
|
+ react_name = (
|
|
|
+ reaction.emoji
|
|
|
+ if isinstance(reaction.emoji, str)
|
|
|
+ else f":{reaction.emoji.name}:"
|
|
|
+ )
|
|
|
notif = f"{user.name} {react_name}'d your message '{content}' in {channel_name}"
|
|
|
user = await self.discord_client.fetch_user(sender_id)
|
|
|
await user.send(notif)
|
|
@@ -55,17 +66,22 @@ class DiscordBot(rollbot.Rollbot[discord.Message]):
|
|
|
async def parse(self, msg: discord.Message) -> rollbot.Message:
|
|
|
# TODO might be nice to only read attachments lazily
|
|
|
|
|
|
- attachments = [rollbot.Attachment(
|
|
|
- name=att.filename,
|
|
|
- body=await att.read(),
|
|
|
- ) for att in msg.attachments]
|
|
|
+ attachments = [
|
|
|
+ rollbot.Attachment(
|
|
|
+ name=att.filename,
|
|
|
+ body=await att.read(),
|
|
|
+ )
|
|
|
+ for att in msg.attachments
|
|
|
+ ]
|
|
|
|
|
|
if msg.reference is not None:
|
|
|
channel = await self.discord_client.fetch_channel(msg.channel.id)
|
|
|
- attachments.append(rollbot.Attachment(
|
|
|
- name="reply",
|
|
|
- body=await channel.fetch_message(msg.reference.resolved.id),
|
|
|
- ))
|
|
|
+ attachments.append(
|
|
|
+ rollbot.Attachment(
|
|
|
+ name="reply",
|
|
|
+ body=await channel.fetch_message(msg.reference.resolved.id),
|
|
|
+ )
|
|
|
+ )
|
|
|
|
|
|
return rollbot.Message(
|
|
|
origin_id="DISCORD",
|
|
@@ -73,8 +89,9 @@ class DiscordBot(rollbot.Rollbot[discord.Message]):
|
|
|
sender_id=str(msg.author.id),
|
|
|
message_id=str(msg.id),
|
|
|
timestamp=msg.created_at,
|
|
|
- origin_admin="RollbotAdmin" in [r.name for r in getattr(msg.author, "roles", [])],
|
|
|
- channel_admin=False, # TODO - implement this if discord allows it
|
|
|
+ origin_admin="RollbotAdmin"
|
|
|
+ in [r.name for r in getattr(msg.author, "roles", [])],
|
|
|
+ channel_admin=False, # TODO - implement this if discord allows it
|
|
|
sender_name=msg.author.name,
|
|
|
text=msg.content,
|
|
|
attachments=attachments,
|
|
@@ -117,7 +134,8 @@ class DiscordBot(rollbot.Rollbot[discord.Message]):
|
|
|
if len(files) > 0:
|
|
|
args["files"] = files
|
|
|
|
|
|
- message = await channel.send(**args)
|
|
|
+ # TODO add abilitly to disable silent?
|
|
|
+ message = await channel.send(silent=True, **args)
|
|
|
for react in reacts:
|
|
|
await message.add_reaction(react)
|
|
|
|