Skip to content

Commit

Permalink
Merge pull request #16 from tudou2/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
congxuma committed May 9, 2023
2 parents 1b2d612 + 95623a3 commit ec4b459
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 13 deletions.
6 changes: 4 additions & 2 deletions channel/wechatcom/wechatcomapp_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def send(self, reply: Reply, context: Context):
image_storage = io.BytesIO()
for block in pic_res.iter_content(1024):
image_storage.write(block)
if (sz := fsize(image_storage)) >= 10 * 1024 * 1024:
sz = fsize(image_storage)
if sz >= 10 * 1024 * 1024:
logger.info("[wechatcom] image too large, ready to compress, sz={}".format(sz))
image_storage = compress_imgfile(image_storage, 10 * 1024 * 1024 - 1)
logger.info("[wechatcom] image compressed, sz={}".format(fsize(image_storage)))
Expand All @@ -109,7 +110,8 @@ def send(self, reply: Reply, context: Context):
logger.info("[wechatcom] sendImage url={}, receiver={}".format(img_url, receiver))
elif reply.type == ReplyType.IMAGE: # 从文件读取图片
image_storage = reply.content
if (sz := fsize(image_storage)) >= 10 * 1024 * 1024:
sz = fsize(image_storage)
if sz >= 10 * 1024 * 1024:
logger.info("[wechatcom] image too large, ready to compress, sz={}".format(sz))
image_storage = compress_imgfile(image_storage, 10 * 1024 * 1024 - 1)
logger.info("[wechatcom] image compressed, sz={}".format(fsize(image_storage)))
Expand Down
2 changes: 1 addition & 1 deletion channel/wechatmp/passive_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import web
from wechatpy import parse_message
from wechatpy.replies import ImageReply, VoiceReply, create_reply

import textwrap
from bridge.context import *
from bridge.reply import *
from channel.wechatmp.common import *
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.alpine.latest
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ RUN chmod +x /entrypoint.sh \

USER noroot

ENTRYPOINT ["docker/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker/Dockerfile.latest
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ RUN chmod +x /entrypoint.sh \

USER noroot

ENTRYPOINT ["docker/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
5 changes: 3 additions & 2 deletions lib/itchat/components/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def auto_login(self, hotReload=False, statusStorageDir='itchat.pkl',
self.useHotReload = hotReload
self.hotReloadDir = statusStorageDir
if hotReload:
if rval:=self.load_login_status(statusStorageDir,
loginCallback=loginCallback, exitCallback=exitCallback):
rval=self.load_login_status(statusStorageDir,
loginCallback=loginCallback, exitCallback=exitCallback)
if rval:
return
logger.error('Hot reload failed, logging in normally, error={}'.format(rval))
self.logout()
Expand Down
6 changes: 3 additions & 3 deletions plugins/banwords/banwords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pennis
干穴
开苞
口活
口交
狼友
春药
风艳阁
Expand Down Expand Up @@ -174,7 +175,6 @@ pennis
爱图公园
色色五月天
鹿城娱乐
色色
幼香阁
隐窝窝
乱伦熟女网
Expand All @@ -191,7 +191,6 @@ pennis
国家主要部委
国民党
国民党万岁
台办
台湾党
台湾帝国
台湾共产党
Expand Down Expand Up @@ -275,7 +274,8 @@ g网
春宫图
成人影视
xing奴隶
性奴隶
奴隶
性奴
极度高潮
乳房照
膣壁
Expand Down
30 changes: 28 additions & 2 deletions plugins/plugin_getnews/getnews.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,33 @@ def on_handle_context(self, e_context: EventContext):
e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑

if re.match(r"我是.*", content):
if re.search(r"微博|weibo|wb", content) and len(content) <= 5:
reply = Reply()
reply.type = ReplyType.TEXT

#接口信息 https://tophub.today/ | https://www.alapi.cn/api/view/49

url = "https://v2.alapi.cn/api/tophub"
headers = {'Content-Type': "application/x-www-form-urlencoded"}
payload = "token="+getnews_api_token+"&id=KqndgxeLl9"

#获取新闻
req = requests.request("POST", url, data=payload, headers=headers)
news_json = json.loads(req.text)

news_date = news_json['data']['last_update']

output = news_date + ' 更新\n'
for i in range(min(len(news_json['data']['list']), 15)):
item = f'%2s.' %str(i+1) + news_json['data']['list'][i]['title'] + ' / '+ news_json['data']['list'][i]['other'] + '\n'
output= output + item

reply.content = output

e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑

if re.match(r"我是.*", content) and len(content) <= 12:
reply = Reply()
reply.type = ReplyType.TEXT

Expand Down Expand Up @@ -130,5 +156,5 @@ def on_handle_context(self, e_context: EventContext):
# e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑

def get_help_text(self, **kwargs):
help_text = "输入今日新闻,获取今天新闻\n输入今日图片,获取今日摄影"
help_text = "输入今日新闻,获取今天新闻\n输入今日图片,获取今日摄影\n输入微博,获取微博热榜"
return help_text
3 changes: 2 additions & 1 deletion translate/baidu/baidu_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def translate(self, query: str, from_lang: str = "", to_lang: str = "en") -> str
while retry_cnt:
r = requests.post(self.url, params=payload, headers=headers)
result = r.json()
if errcode := result.get("error_code", "52000") != "52000":
errcode = result.get("error_code", "52000")
if errcode != "52000":
if errcode == "52001" or errcode == "52002":
retry_cnt -= 1
continue
Expand Down

0 comments on commit ec4b459

Please sign in to comment.