Skip to content

Commit

Permalink
Check for sending permissions before doing anything
Browse files Browse the repository at this point in the history
  • Loading branch information
greentore committed Jul 22, 2024
1 parent 6dc9a9d commit 34a63c7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sadpanda/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from maubot.handlers import command
from mautrix.types import (
ContentURI,
EventType,
ImageInfo,
MediaMessageEventContent,
MessageType,
Expand Down Expand Up @@ -203,12 +204,19 @@ async def get_thumb(self, gallery: gmetadata):
@command.passive(r"https?://e[-x]hentai\.org/(?:s|g|mpv)")
async def handler(self, evt: MessageEvent, _match):
assert isinstance(evt.content, TextMessageEventContent)
assert self.client.state_store
can_send = await self.client.state_store.has_power_level(
evt.room_id, self.client.mxid, EventType.ROOM_MESSAGE
)
if (
evt.sender in self.blacklist
or evt.content.msgtype not in self.allowed_msgtypes
or evt.content.get_edit()
):
return
if not can_send:
self.log.warning(f"Not allowed to send messages in {evt.room_id}")
return

evt.content.trim_reply_fallback()
gid_dict, page_list = get_gids(evt.content.body)
Expand Down

0 comments on commit 34a63c7

Please sign in to comment.