This commit is contained in:
Malasaur 2025-12-17 00:27:01 +01:00
parent 715d0527bf
commit 8d20e77f85
No known key found for this signature in database
2 changed files with 73 additions and 42 deletions

View file

@ -5,7 +5,6 @@ from typing import Callable, Literal
from uuid import uuid4 from uuid import uuid4
from aiohttp import ClientSession from aiohttp import ClientSession
from config import Config
class User: class User:
@ -82,6 +81,10 @@ class MessageMention:
self.length = length self.length = length
self.recipient = recipient self.recipient = recipient
@classmethod
def newMessage(cls, recipient: User):
return Message("X", mentions=[cls(0, 1, recipient)])
def get(self) -> str: def get(self) -> str:
return ( return (
f"{self.start}:{self.length}:{self.recipient.number or self.recipient.id}" f"{self.start}:{self.length}:{self.recipient.number or self.recipient.id}"
@ -132,6 +135,36 @@ class Message:
self.quote = quote self.quote = quote
self.edit = edit self.edit = edit
def __add__(self, b) -> "Message":
a = Message(
text=self.text,
user=self.user,
group=self.group,
timestamp=self.timestamp,
attachments=self.attachments,
view_once=self.view_once,
sticker=self.sticker,
mentions=self.mentions,
styles=self.styles,
quote=self.quote,
edit=self.edit,
)
if isinstance(b, Message):
a.text = a.text or ""
for mention in b.mentions:
a.mentions.append(
MessageMention(
mention.start + len(a.text),
mention.length + len(a.text),
mention.recipient,
),
)
if b.text:
a.text += b.text
return a
class Poll: class Poll:
def __init__( def __init__(
@ -274,8 +307,6 @@ class Signal:
return await self._post("remoteDelete", **params) return await self._post("remoteDelete", **params)
# TODO: implement polls
"""
async def sendPoll(self, poll: Poll, recipient: User | Group): async def sendPoll(self, poll: Poll, recipient: User | Group):
params: dict = {} params: dict = {}
if isinstance(recipient, User): if isinstance(recipient, User):
@ -297,7 +328,6 @@ class Signal:
poll.user = User.self() poll.user = User.self()
return result return result
"""
async def listGroups(self) -> list[Group]: async def listGroups(self) -> list[Group]:
return [ return [
@ -384,6 +414,7 @@ class Signal:
(await self.getGroup(groupId)) if groupId else None (await self.getGroup(groupId)) if groupId else None
) )
if message or sticker:
msg = Message( msg = Message(
text=message, text=message,
user=msg_user, user=msg_user,

View file

@ -1,11 +1,11 @@
from libbot import signal from libbot import signal
from libsignal import Message from libsignal import Message, MessageMention
@signal.onMessage() @signal.onMessage()
async def onMessage(message: Message): async def onMessage(message: Message):
if message.user and message.text and "@everyone" in message.text: if message.user and message.group and message.text and "@everyone" in message.text:
await signal.sendMessage( msg = Message("", quote=message)
Message("EVERYBODY LISTEN!!!!", quote=message), for user in message.group.members:
message.group or message.user, msg += MessageMention.newMessage(user)
) await signal.sendMessage(msg, message.group)