forked from UsergeTeam/Userge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logbot.py
55 lines (40 loc) · 1.43 KB
/
logbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# pylint: disable=missing-module-docstring
#
# Copyright (C) 2020-2021 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/UsergeTeam/Userge/blob/master/LICENSE >
#
# All rights reserved.
__all__ = ["send_msg", "reply_last_msg", "edit_last_msg", "del_last_msg", "end"]
def _log(func):
def wrapper(text, log=None, tmp=None):
if log and callable(log):
if tmp:
log(tmp, text)
else:
log(text)
func(text)
return wrapper
def _send_data(*args) -> None:
with open("logs/logbot.stdin", 'a') as l_b:
l_b.write(f"{' '.join(args)}\n")
@_log
def send_msg(text: str, log=None, tmp=None) -> None: # pylint: disable=unused-argument
""" send message """
_send_data("sendMessage", text)
@_log
def reply_last_msg(text: str, log=None, tmp=None) -> None: # pylint: disable=unused-argument
""" reply to last message """
_send_data("replyLastMessage", text)
@_log
def edit_last_msg(text: str, log=None, tmp=None) -> None: # pylint: disable=unused-argument
""" edit last message """
_send_data("editLastMessage", text)
def del_last_msg() -> None:
""" delete last message """
_send_data("deleteLastMessage")
def end() -> None:
""" end bot session """
_send_data("quit")