This commit is contained in:
机器人总动员 2021-05-05 16:13:28 +08:00
parent b7d01edd2c
commit bec8b109cf
10 changed files with 22 additions and 121 deletions

BIN
circle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
font.ttf Normal file

Binary file not shown.

View File

@ -1,7 +1,10 @@
import time
import connector
import telegram
from telegram.ext import CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackQueryHandler
from config import TOKEN
import schedule
bot = telegram.Bot(token=TOKEN)
@ -40,5 +43,11 @@ def chat_content_exec(update, context):
print("---------------------------")
def check_schedule():
while True:
schedule.run_pending()
time.sleep(1)
start_handler = CommandHandler('start', start)
chat_content_handler = MessageHandler(Filters.text, chat_content_exec)

10
main.py
View File

@ -1,6 +1,14 @@
from telegram.ext import Updater
from config import TOKEN
from func import start_handler, chat_content_handler
from func import start_handler, chat_content_handler, check_schedule
import schedule
import task
import threading
# schedule.every().day.at('16:20').do(task).tag('task')
schedule.every(1).minutes.do(task).tag('task')
threading.Thread(target=check_schedule).start()
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher

View File

@ -1,5 +1,4 @@
import re
import redis
import jieba
import jieba.posseg as pseg
import wordcloud
@ -21,12 +20,12 @@ for i in key_list:
group_list.append(i[:i.find("_")])
# print(group_list)
mk = imageio.imread("/root/Jupyter/circle.png")
mk = imageio.imread("/root/word_cloud_bot/circle.png")
# 构建并配置词云对象w注意要加scale参数提高清晰度
w = wordcloud.WordCloud(width=800,
height=800,
background_color='white',
font_path='/root/Jupyter/hanyiqihei.ttf',
font_path='/root/word_cloud_bot/font.ttf',
mask=mk,
scale=5)
@ -127,3 +126,5 @@ for group in group_list:
except Exception as e:
print(e)
continue
r.flushall()
print("已清空数据库")

View File

@ -1,21 +0,0 @@
import redis
# 连接 redis
# 指定主机地址port与服务器连接redis默认数据库有16个默认db是0
# r = redis.Redis(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True) # password='**'
# print(r.get('foo'))
# r.set('foo', '[1,2,3]')
# print(r.get('foo'))
# print(r.keys())
# r.delete('foo')
# print(r.keys())
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True)
# r = redis.Redis(connection_pool=pool)
# r.set('foo', 'Bar')
# print(r.get('foo'))
def get_connection():
return redis.StrictRedis(connection_pool=pool)

View File

@ -1,47 +0,0 @@
# encoding=utf-8
import jieba
import jieba.posseg as pseg
import time # 引入time模块
import redis
import connector
test_word = '''
📜 ZUOLUOTV 例行群规广播 📜
📅 2021年5月5日
截至今天08:00 本群共有11374位群友
自由并不意味着没有规则群内稳定和持续的交流氛围依靠的是大家对规则的尊重
📖 ZUOLUOTV群管理规范 📖
🈯 本群提倡一切事务合法合规操作
🔞 不允许传播违法黑灰产相关内容
1.必Ban:传播黑灰产贩卖手机卡银行卡个人信息
2.必Ban:传播色情暴力低俗内容
3.必Ban:群发广告ID或头像中带广告
4.别聊政治敏感话题不鼓励聊翻墙机场等话题原因请看WHY
5.别搞人身攻击别搞地域黑别发布仇恨言论别骚扰异性
6.别做伸手党先看资料索引学会谷歌搜索善看群聊记录
7.不要用语音不要连续刷屏恶意刷屏将被Ban
8.鼓励原创分享分享外链尽量是科技数码摄影旅行主题
9.违反群规者飞机场见异议可私信管理员精力时间有限私聊不解答公开问题
'''
start_time = float(time.time())
# words = pseg.cut("我爱北京天安门") # jieba默认模式
jieba.enable_paddle() # 启动paddle模式。 0.40版之后开始支持,早期版本不支持
words = pseg.cut(test_word, use_paddle=True) # paddle模式
word_list = []
for word, flag in words:
# print(word + "\t" + flag)
if flag in ["n", "nr", "nz", "PER", "f", "ns", "LOC", "s", "nt", "ORG", "nw"]:
word_list.append(word)
r = connector.get_connection()
r.set('foo', 'Bar')
print(r.get('foo'))
print(word_list)
stop_time = float(time.time())
print(stop_time - start_time)

View File

@ -1,12 +0,0 @@
import redis
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True, db=0)
r = redis.StrictRedis(connection_pool=pool)
# r.hset("user", "a", 1)
# r.hincrby('user', "a")
# r.hincrby('user', "b")
print(r.hget("user", "a"))
print(r.hget("user", "b"))
r.delete()

View File

@ -1,33 +0,0 @@
group_name = '-1001403536948_chat_content'
print(group_name[:group_name.find("_")])
word_amount = {}
word_amount['y1111'] = 1
word_amount['y2222'] = 2
word_amount['y3333'] = 4
word_amount['y4444'] = 3
print(word_amount.get("123"))
print(word_amount.get("y4444"))
print(word_amount)
word_amount = sorted(word_amount.items(), key=lambda word: (word[1]))
print(word_amount)
print("--------------")
import re
str = '''
23
'''
rst = re.match(r"^\s+?$", str)
print(rst)
import time
print(time.strftime("%Y年%m月%d", time.localtime()))
print(time.strftime("%H:%M", time.localtime()))

View File

@ -1,4 +0,0 @@
import time # 引入time模块
start_time = int(time.time())
print("当前时间戳为:", int(ticks))