Skip to content

Commit e7cf414

Browse files
committed
EWS: Fix typo, Fix ehForwarderBot#8
ETM: Fallback mechanism for messages with `parse_mode` assigned.
1 parent 4d8cd1a commit e7cf414

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

CONTRIBUTING.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ If you need help, or want to talk to the authors, feel free to chat with us at o
2020
* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
2121
* **Explain which behavior you expected to see instead and why.**
2222
* **If the problem wasn't triggered by a specific action**, describe what you were doing before the problem happened and share more information using the guidelines below.
23+
* **Provide log related to the issue.** Use `python3 main.py -vv` to start the logging process, and submit the entire log from the first step you performed.
2324

2425
Provide more context by answering these questions:
2526

@@ -32,6 +33,9 @@ Include details about your configuration and environment:
3233
* **What's the name and version of the OS you're using?**
3334
* **Which channel caused the problem?** Or did the framework cause it?
3435

36+
!!! attention
37+
When submitting your log, please remember to hide your private information.
38+
3539
## Suggesting enhancements
3640

3741
If you have any suggestions, feel free to raise it up in the issue list. Please try to provide as much details as you can, that includes:

docs/CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ If you need help, or want to talk to the authors, feel free to chat with us at o
2020
* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
2121
* **Explain which behavior you expected to see instead and why.**
2222
* **If the problem wasn't triggered by a specific action**, describe what you were doing before the problem happened and share more information using the guidelines below.
23+
* **Provide log related to the issue.** Use `python3 main.py -vv` to start the logging process, and submit the entire log from the first step you performed.
2324

2425
Provide more context by answering these questions:
2526

docs/EWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# EFB WeChat Slave Channel
22

3-
EFB WeChat Slave Channel is a slave channel for EFB based on [ItChat](https://github.com/littlecodersh/ItChat) and WeChat Web <span style="font-size: 0.5em;">(rev.eng.)</span> API.
3+
EFB WeChat Slave (EWS) is a slave channel for EFB based on [ItChat](https://github.com/littlecodersh/ItChat) and WeChat Web <span style="font-size: 0.5em;">(rev.eng.)</span> API.
44

55
## Specs
66
* Unique name: `eh_wechat_slave`

plugins/eh_telegram_master/__init__.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,31 @@ def process_msg(self, msg):
236236
if tg_chat_assoced and append_last_msg:
237237
self.logger.debug("%s, process_msg_step_3_0_1", xid)
238238
msg.text = "%s\n%s" % (last_msg.text, msg.text)
239-
tg_msg = self.bot.bot.editMessageText(chat_id=tg_dest,
240-
message_id=last_msg.master_msg_id.split(".", 1)[1],
241-
text=msg_template % msg.text,
242-
parse_mode=parse_mode)
239+
try:
240+
tg_msg = self.bot.bot.editMessageText(chat_id=tg_dest,
241+
message_id=last_msg.master_msg_id.split(".", 1)[1],
242+
text=msg_template % msg.text,
243+
parse_mode=parse_mode)
244+
except telegram.error.BadRequest:
245+
tg_msg = self.bot.bot.editMessageText(chat_id=tg_dest,
246+
message_id=last_msg.master_msg_id.split(".", 1)[1],
247+
text=msg_template % msg.text)
243248
else:
244249
self.logger.debug("%s, process_msg_step_3_0_3", xid)
245-
tg_msg = self.bot.bot.sendMessage(tg_dest, text=msg_template % msg.text, parse_mode=parse_mode)
250+
try:
251+
tg_msg = self.bot.bot.sendMessage(tg_dest, text=msg_template % msg.text, parse_mode=parse_mode)
252+
except telegram.error.BadRequest:
253+
tg_msg = self.bot.bot.sendMessage(tg_dest, text=msg_template % msg.text)
246254
self.logger.debug("%s, process_msg_step_3_0_4, tg_msg = %s", xid, tg_msg)
247255
self.logger.debug("%s, process_msg_step_3_1", xid)
248256
elif msg.type == MsgType.Link:
249-
self.logger.info("Link msg:\n%s\n%s\n%s", msg.attributes["url"], msg.attributes["title"], msg.attributes['description'])
250257
text = "🔗 <a href=\"%s\">%s</a>\n%s" % (urllib.parse.quote(msg.attributes["url"], safe="?=&#:/"),
251258
html.escape(msg.attributes["title"]),
252259
html.escape(msg.attributes["description"]))
253-
tg_msg = self.bot.bot.sendMessage(tg_dest, text=msg_template % text, parse_mode="HTML")
260+
try:
261+
tg_msg = self.bot.bot.sendMessage(tg_dest, text=msg_template % text, parse_mode="HTML")
262+
except telegram.error.BadRequest:
263+
tg_msg = self.bot.bot.sendMessage(tg_dest, text=msg_template % msg.text)
254264
elif msg.type in [MsgType.Image, MsgType.Sticker]:
255265
self.logger.debug("%s, process_msg_step_3_2", xid)
256266
self.logger.info("Received %s \nPath: %s\nSize: %s\nMIME: %s", msg.type, msg.path,
@@ -751,6 +761,7 @@ def msg(self, bot, update):
751761
return self._reply_error(bot, update, "Internal error: Channel not found.")
752762
try:
753763
m = EFBMsg(self)
764+
m.uid = "%s.%s" % (update.message.chat.id, update.message.message_id)
754765
mtype = get_msg_type(update.message)
755766
# Chat and author related stuff
756767
m.origin['uid'] = update.message.from_user.id

plugins/eh_wechat_slave.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ def incomeMsgMeta(func):
2121
def wcFunc(self, msg, isGroupChat=False):
2222
logger = logging.getLogger("plugins.eh_wechat_slave.incomeMsgMeta")
2323
mobj = func(self, msg, isGroupChat)
24+
mobj.uid = msg.get("MsgId", time.time())
2425
me = msg['FromUserName'] == itchat.get_friends()[0]['UserName']
2526
logger.debug("me, %s", me)
2627
if me:
2728
msg['FromUserName'], msg['ToUserName'] = msg['ToUserName'], msg['FromUserName']
2829
FromUser = self.search_user(UserName=msg['FromUserName']) or \
29-
[{"NickName": "User error. (UE01)", "RemarkName": "User error. (UE01)", "Uin": 0}]
30+
[{"NickName": "Chat not found. (UE01)", "RemarkName": "Chat not found. (UE01)", "Uin": 0}]
3031
FromUser = FromUser[0]
3132
logger.debug("From user, %s", FromUser)
3233
if isGroupChat:
@@ -236,6 +237,13 @@ def search_user(self, UserName=None, uid=None, uin=None, name=None, ActualUserNa
236237
if all(i is None for i in [UserName, uid, uin, name]):
237238
raise ValueError("At least one of [UserName, uid, uin, name] should be provided.")
238239

240+
if UserName in self.SYSTEM_USERNAMES or uin in self.SYSTEM_USERNAMES:
241+
sys_chat_id = UserName or uin
242+
return [{"UserName": sys_chat_id,
243+
"NickName": "System (%s)" % sys_chat_id,
244+
"RemarkName": "System (%s)" % sys_chat_id,
245+
"Uin": sys_chat_id}]
246+
239247
for i in itchat.get_friends(refresh) + itchat.get_mps(refresh):
240248
data = {"nickname": i.get('NickName', None),
241249
"alias": i.get("RemarkName", None),
@@ -257,7 +265,7 @@ def search_user(self, UserName=None, uid=None, uin=None, name=None, ActualUserNa
257265
"uin": i.get("Uin", None)}
258266
for j in fallback_order:
259267
if str(crc32(data[j.lower()].encode("utf-8"))) == uid:
260-
result.append(j.copy())
268+
result.append(i.copy())
261269
if str(i.get('Uin', '')) == uin or \
262270
str(i.get('NickName', '')) == name or \
263271
str(i.get('DisplayName', '')) == name or \
@@ -719,7 +727,7 @@ def uin_rate(self, param=""):
719727

720728
def add_friend(self, UserName=None, status=2, ticket="", UserInfo={}):
721729
if not UserName:
722-
return "Username is empty. (UE01)"
730+
return "Username is empty. (UE02)"
723731
try:
724732
itchat.add_friend(UserName, status, ticket, UserInfo)
725733
return "Success."
@@ -734,13 +742,14 @@ def get_chats(self, group=True, user=True):
734742
t[0]['NickName'] = "File Helper"
735743
t[0]['UserName'] = "filehelper"
736744
t[0]['RemarkName'] = ""
745+
t[0]['Uin'] = "filehelper"
737746
for i in t:
738747
r.append({
739748
'channel_name': self.channel_name,
740749
'channel_id': self.channel_id,
741750
'name': i['NickName'],
742751
'alias': i['RemarkName'] or i['NickName'],
743-
'uid': self.get_uid(NickName=i['NickName'], alias=i.get("RemarkName", None), Uin=i.get("Uin", None)),
752+
'uid': self.get_uid(UserName=i['UserName'], NickName=i['NickName'], alias=i.get("RemarkName", None), Uin=i.get("Uin", None)),
744753
'type': MsgSource.User
745754
})
746755
if group:

0 commit comments

Comments
 (0)