修复队列发送Bug

This commit is contained in:
机器人总动员 2021-05-09 12:44:53 +08:00
parent a6926e1287
commit 225e27bf88
3 changed files with 12 additions and 18 deletions

View File

@ -1,4 +1,3 @@
#! /bin/sh \ #! /bin/sh \
cd /root/word_cloud_bot && python3 main.py >> output 2>&1 & cd /root/word_cloud_bot && python3 main.py >> output 2>&1 &
cd /root/word_cloud_bot && bash restart.sh 2>&1 &
tail -f /dev/null tail -f /dev/null

View File

@ -9,7 +9,7 @@ do
us=`free | awk 'NR==2{print $3}'` us=`free | awk 'NR==2{print $3}'`
to=`free | awk 'NR==2{print $2}'` to=`free | awk 'NR==2{print $2}'`
mem=`expr "scale=2;($us-$bu-$ca)/$to" |bc -l | cut -d. -f2` mem=`expr "scale=2;($us-$bu-$ca)/$to" |bc -l | cut -d. -f2`
if(($mem >= 75)) if(($mem >= 90))
then then
echo "restart" echo "restart"
killall -9 python3 killall -9 python3

27
task.py
View File

@ -52,12 +52,8 @@ def do_task():
print("当前群组处理耗时:" + str(stop_time - start_time)) print("当前群组处理耗时:" + str(stop_time - start_time))
print("---------------------------") print("---------------------------")
except Exception as e: except Exception as e:
print("群组: {} | 处理失败,请检查报错!".format(group)) print("群组: {} | 处理失败,可能是机器人已经被移出群组,请检查报错!".format(group))
print(e) print(e)
bot.send_message(
chat_id=group,
text="当前聊天数据量过小,嗨起来吧~"
)
time.sleep(1) time.sleep(1)
@ -167,12 +163,6 @@ def generate(group):
top_5_user += "\t\t\t\t\t\t\t\t" + "🎖`" + str(user_message_amount[i][0]) + "`" + " 贡献: " + str( top_5_user += "\t\t\t\t\t\t\t\t" + "🎖`" + str(user_message_amount[i][0]) + "`" + " 贡献: " + str(
user_message_amount[i][1]) + "\n" user_message_amount[i][1]) + "\n"
# print(top_5_user) # print(top_5_user)
string = " ".join(word_list)
# 将string变量传入w的generate()方法,给词云输入文字
w.generate(string)
# 将词云图片导出到当前文件夹
w.to_file('{}_chat_word_cloud.png'.format(group))
bot.send_message( bot.send_message(
chat_id=group, chat_id=group,
text="🏵 今日活跃用户排行榜 🏵\n" text="🏵 今日活跃用户排行榜 🏵\n"
@ -193,6 +183,11 @@ def generate(group):
) )
try: try:
string = " ".join(word_list)
# 将string变量传入w的generate()方法,给词云输入文字
w.generate(string)
# 将词云图片导出到当前文件夹
w.to_file('{}_chat_word_cloud.png'.format(group))
bot.send_photo( bot.send_photo(
chat_id=group, chat_id=group,
photo=open("{}_chat_word_cloud.png".format(group), "rb") photo=open("{}_chat_word_cloud.png".format(group), "rb")
@ -200,11 +195,11 @@ def generate(group):
os.remove("{}_chat_word_cloud.png".format(group)) os.remove("{}_chat_word_cloud.png".format(group))
except Exception as e: except Exception as e:
print(e) print(e)
bot.send_message( print("词云图片生成失败")
chat_id=group, # bot.send_message(
text="当前聊天数据量过小,嗨起来吧~" # chat_id=group,
) # text="当前聊天数据量过小,嗨起来吧~"
return # )
def flush_redis(): def flush_redis():