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 aiohttp import ClientSession
from config import Config
class User:
@ -82,6 +81,10 @@ class MessageMention:
self.length = length
self.recipient = recipient
@classmethod
def newMessage(cls, recipient: User):
return Message("X", mentions=[cls(0, 1, recipient)])
def get(self) -> str:
return (
f"{self.start}:{self.length}:{self.recipient.number or self.recipient.id}"
@ -132,6 +135,36 @@ class Message:
self.quote = quote
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:
def __init__(
@ -274,8 +307,6 @@ class Signal:
return await self._post("remoteDelete", **params)
# TODO: implement polls
"""
async def sendPoll(self, poll: Poll, recipient: User | Group):
params: dict = {}
if isinstance(recipient, User):
@ -297,7 +328,6 @@ class Signal:
poll.user = User.self()
return result
"""
async def listGroups(self) -> list[Group]:
return [
@ -384,6 +414,7 @@ class Signal:
(await self.getGroup(groupId)) if groupId else None
)
if message or sticker:
msg = Message(
text=message,
user=msg_user,

View file

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