Fire
This commit is contained in:
parent
715d0527bf
commit
8d20e77f85
2 changed files with 73 additions and 42 deletions
103
libsignal.py
103
libsignal.py
|
|
@ -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,44 +414,45 @@ class Signal:
|
|||
(await self.getGroup(groupId)) if groupId else None
|
||||
)
|
||||
|
||||
msg = Message(
|
||||
text=message,
|
||||
user=msg_user,
|
||||
group=msg_group,
|
||||
timestamp=timestamp,
|
||||
sticker=sticker,
|
||||
view_once=viewOnce,
|
||||
)
|
||||
if message or sticker:
|
||||
msg = Message(
|
||||
text=message,
|
||||
user=msg_user,
|
||||
group=msg_group,
|
||||
timestamp=timestamp,
|
||||
sticker=sticker,
|
||||
view_once=viewOnce,
|
||||
)
|
||||
|
||||
await self._post(
|
||||
"sendReceipt",
|
||||
recipient=msg_user.id,
|
||||
targetTimestamp=timestamp,
|
||||
type="viewed",
|
||||
)
|
||||
await self._post(
|
||||
"sendReceipt",
|
||||
recipient=msg_user.id,
|
||||
targetTimestamp=timestamp,
|
||||
type="viewed",
|
||||
)
|
||||
|
||||
if not user and not group:
|
||||
return await func(msg)
|
||||
if not user and not group:
|
||||
return await func(msg)
|
||||
|
||||
if isinstance(user, User) and user.id == msg_user.id:
|
||||
return await func(msg)
|
||||
if isinstance(user, User) and user.id == msg_user.id:
|
||||
return await func(msg)
|
||||
|
||||
if (
|
||||
isinstance(group, Group)
|
||||
and msg_group
|
||||
and group.id == msg_group.id
|
||||
):
|
||||
return await func(msg)
|
||||
if (
|
||||
isinstance(group, Group)
|
||||
and msg_group
|
||||
and group.id == msg_group.id
|
||||
):
|
||||
return await func(msg)
|
||||
|
||||
if isinstance(user, list):
|
||||
for usr in user:
|
||||
if usr.id == msg_user.id:
|
||||
return await func(msg)
|
||||
if isinstance(user, list):
|
||||
for usr in user:
|
||||
if usr.id == msg_user.id:
|
||||
return await func(msg)
|
||||
|
||||
if isinstance(group, list) and msg_group:
|
||||
for grp in group:
|
||||
if grp.id == msg_group.id:
|
||||
return await func(msg)
|
||||
if isinstance(group, list) and msg_group:
|
||||
for grp in group:
|
||||
if grp.id == msg_group.id:
|
||||
return await func(msg)
|
||||
|
||||
self._hooks.append(callback)
|
||||
return func
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue