Skip to content

Commit

Permalink
feat(ver): v0.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
wyapx committed Aug 15, 2024
1 parent 4d27835 commit 93e7634
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 96 deletions.
6 changes: 4 additions & 2 deletions lagrange/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def __init__(
app_info: AppInfo,
device_info: DeviceInfo,
sig_info: SigInfo,
sign_provider: Optional[Callable[[str, int, bytes], Coroutine[None, None, dict]]] = None,
sign_provider: Optional[
Callable[[str, int, bytes], Coroutine[None, None, dict]]
] = None,
use_ipv6=True,
):
if uin and not sig_info.uin:
Expand Down Expand Up @@ -142,7 +144,7 @@ async def _push_handle_loop(self):
try:
await self.push_handler(sso)
except Exception as e:
log.root.error("Unhandled exception on push handler", exc_info=e)
log.root.exception("Unhandled exception on push handler", exc_info=e)

async def wait_closed(self) -> None:
try:
Expand Down
2 changes: 2 additions & 0 deletions lagrange/client/server_push/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ async def msg_push_handler(client: "Client", sso: SSOPacket):
target_uid=unpack_dict(info, "5.3.1", b"").decode(),
duration=unpack_dict(info, "5.3.2"),
)
elif sub_typ == 21: # set/unset essence msg
pass # todo
else:
logger.debug(
"unknown sub_type %d: %s"
Expand Down
51 changes: 47 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

from lagrange import Lagrange, install_loguru
from lagrange.client.client import Client
from lagrange.client.events.group import GroupMessage
from lagrange.client.events.group import GroupMessage, GroupSign, GroupReaction
from lagrange.client.events.service import ServerKick
from lagrange.client.message.elems import At, Text
from lagrange.client.message.elems import At, Text, Quote, Emoji


async def msg_handler(client: Client, event: GroupMessage):
#print(event)
# print(event)
if event.msg.startswith("114514"):
msg_seq = await client.send_grp_msg([At.build(event), Text("1919810")], event.grp_id)
msg_seq = await client.send_grp_msg(
[At.build(event), Text("1919810")], event.grp_id
)
await asyncio.sleep(5)
await client.recall_grp_msg(event.grp_id, msg_seq)
elif event.msg.startswith("imgs"):
Expand All @@ -31,6 +33,45 @@ async def handle_kick(client: "Client", event: "ServerKick"):
await client.stop()


async def handle_grp_sign(client: "Client", event: "GroupSign"):
a = "闲着没事爱打卡,可以去找个班上"
k = None
uid = None
while True:
kk = await client.get_grp_members(event.grp_id, k)
for m in kk.body:
if m.account.uin == event.uin:
uid = m.account.uid
break
if uid:
break
if kk.next_key:
k = kk.next_key
else:
raise ValueError(f"cannot find member: {event.uin}")

await client.send_grp_msg(
[At(f"@{event.nickname} ", event.uin, uid), Text(a)], event.grp_id
)


async def handle_group_reaction(client: "Client", event: "GroupReaction"):
msg = (await client.get_grp_msg(event.grp_id, event.seq))[0]
mi = (await client.get_grp_member_info(event.grp_id, event.uid)).body[0]
if event.is_emoji:
e = Text(chr(event.emoji_id))
else:
e = Emoji(event.emoji_id)
if event.is_increase:
m = "给你点了"
else:
m = "取消了"
await client.send_grp_msg(
[Quote.build(msg), Text(f"{mi.name.string if mi.name else mi.nickname}{m}"), e],
event.grp_id,
)


lag = Lagrange(
int(os.environ.get("LAGRANGE_UIN", "0")),
"linux",
Expand All @@ -41,6 +82,8 @@ async def handle_kick(client: "Client", event: "ServerKick"):

lag.subscribe(GroupMessage, msg_handler)
lag.subscribe(ServerKick, handle_kick)
lag.subscribe(GroupSign, handle_grp_sign)
lag.subscribe(GroupReaction, handle_group_reaction)


lag.launch()
Loading

0 comments on commit 93e7634

Please sign in to comment.