Skip to content

Commit 64e4414

Browse files
committed
Merge tag 'v1.5.5' into extend
ETM: Bug fix.
2 parents af24a8e + 397945f commit 64e4414

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if sys.version_info.major < 3:
1111
raise Exception("Python 3.x is required. Your version is %s." % sys.version)
1212

13-
__version__ = "1.5.0"
13+
__version__ = "1.5.5"
1414

1515
parser = argparse.ArgumentParser(description="EH Forwarder Bot is an extensible chat tunnel framework which allows "
1616
"users to contact people from other chat platforms, and ultimately "

plugins/eh_telegram_master/__init__.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import pydub
1616
import threading
1717
import traceback
18+
import base64
1819
from . import db, speech
1920
from .whitelisthandler import WhitelistHandler
2021
from channel import EFBChannel, EFBMsg, MsgType, MsgSource, TargetType, ChannelType
@@ -595,7 +596,7 @@ def link_chat_confirm(self, bot, tg_chat_id, tg_msg_id, callback_uid):
595596
txt += "\nWhat would you like to do?"
596597

597598
link_url = "https://telegram.me/%s?startgroup=%s" % (
598-
self.me.username, urllib.parse.quote("%s.%s" % (tg_chat_id, tg_msg_id)))
599+
self.me.username, urllib.parse.quote(self.b64en("%s.%s" % (tg_chat_id, tg_msg_id))))
599600
self.logger.debug("Telegram start trigger for linking chat: %s", link_url)
600601
if linked:
601602
btn_list = [telegram.InlineKeyboardButton("Relink", url=link_url),
@@ -974,7 +975,7 @@ def msg(self, bot, update):
974975
elif mtype == TGMsgType.Audio:
975976
m.type = MsgType.Audio
976977
m.text = "%s - %s\n%s" % (
977-
update.message.audio.title, update.message.audio.perfomer, update.message.caption)
978+
update.message.audio.title, update.message.audio.performer, update.message.caption)
978979
m.path, m.mime = self._download_file(update.message, update.message.audio, m.type)
979980
elif mtype == TGMsgType.Voice:
980981
m.type = MsgType.Audio
@@ -1065,7 +1066,10 @@ def start(self, bot, update, args=[]):
10651066
args: Arguments from message
10661067
"""
10671068
if update.message.from_user.id != update.message.chat.id: # from group
1068-
data = self.msg_storage[args[0]]
1069+
try:
1070+
data = self.msg_storage[self.b64de(args[0])]
1071+
except KeyError:
1072+
update.message.reply_text("Session expired or unknown parameter. (SE02)")
10691073
chat_uid = data["chat_uid"]
10701074
chat_display_name = data["chat_display_name"]
10711075
slave_channel, slave_chat_uid = chat_uid.split('.', 1)
@@ -1267,3 +1271,10 @@ def stop_polling(self, val):
12671271
self.queue.put(None)
12681272
self._stop_polling = val
12691273

1274+
@staticmethod
1275+
def b64en(s):
1276+
return base64.b64encode(s.encode()).decode()
1277+
1278+
@staticmethod
1279+
def b64de(s):
1280+
return base64.b64decode(s).decode()

plugins/eh_wechat_slave.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,19 @@ def wechat_link_msg(self, msg):
458458
@wechat_msg_meta
459459
def wechat_raw_link_msg(self, msg, title, description, image, url):
460460
mobj = EFBMsg(self)
461-
mobj.type = MsgType.Link
462-
mobj.attributes = {
463-
"title": title,
464-
"description": description,
465-
"image": image,
466-
"url": url
467-
}
461+
if url:
462+
mobj.type = MsgType.Link
463+
mobj.attributes = {
464+
"title": title,
465+
"description": description,
466+
"image": image,
467+
"url": url
468+
}
469+
else:
470+
mobj.type = MsgType.Text
471+
mobj.text = "%s\n%s" % (title, description)
472+
if image:
473+
mobj.text += "\n\n%s" % image
468474
return mobj
469475

470476
def wechat_newsapp_msg(self, msg):
@@ -795,7 +801,9 @@ def uin_rate(self, param=""):
795801

796802
users = self.itchat.get_friends(True) + self.itchat.get_mps(True)
797803
users_uin = len([i for i in users if i.get("Uin", None)])
798-
users_all = len(users)
804+
users_all = len(users) or 1
805+
groups_all = groups_all or 1
806+
members_all = members_all or 1
799807

800808
return "`Uin` rate checkup.\n\n" \
801809
"Users + MP: %s/%s (%.2f%%)\n" \
@@ -810,6 +818,7 @@ def uin_rate(self, param=""):
810818
"Usage: {function_name}")
811819
def force_log_out(self, param=""):
812820
self.itchat.logout()
821+
return "Done."
813822

814823
# Command functions
815824

@@ -953,11 +962,7 @@ def _itchat_send_fn(self, fileDir, toUserName=None, mediaId=None, filename=None)
953962
return ReturnValue(rawResponse=r)
954963

955964
try:
956-
fn = kwargs.get("filename", None)
957-
if fn is not None:
958-
return _itchat_send_fn(self.itchat, *args, **kwargs)
959-
else:
960-
return self.itchat.send_file(*args, **kwargs)
965+
_itchat_send_fn(self.itchat, *args, **kwargs)
961966
except Exception as e:
962967
raise EFBMessageError(repr(e))
963968

0 commit comments

Comments
 (0)