mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-20 08:25:50 +08:00
up
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
import base64
|
||||
import threading
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
import telebot
|
||||
from telebot import types
|
||||
from telebot.util import quick_markup
|
||||
|
||||
# 轮播实例
|
||||
|
||||
chat_id = -1001578009023
|
||||
# chat_id = 5568699210
|
||||
|
||||
|
||||
def send_msg(bot, tag='ad', trigger_time=300):
|
||||
# 信号只在一个周期内执行一次|start
|
||||
lock_file = mw.getServerDir() + '/tgbot/lock.json'
|
||||
if not os.path.exists(lock_file):
|
||||
mw.writeFile(lock_file, '{}')
|
||||
|
||||
lock_data = json.loads(mw.readFile(lock_file))
|
||||
if tag in lock_data:
|
||||
diff_time = time.time() - lock_data[tag]['do_time']
|
||||
if diff_time >= trigger_time:
|
||||
lock_data[tag]['do_time'] = time.time()
|
||||
else:
|
||||
return False, 0, 0
|
||||
else:
|
||||
lock_data[tag] = {'do_time': time.time()}
|
||||
mw.writeFile(lock_file, json.dumps(lock_data))
|
||||
# 信号只在一个周期内执行一次|end
|
||||
|
||||
# https://t.me/gjgzs2022 | 19/m
|
||||
# ♻️CMS导航网♻️/💰流量变现💰 | 28/m
|
||||
# CK资源采集 |29/m
|
||||
# 高防服务器CDN请联系玥玥 |3/m
|
||||
keyboard = [
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="海外服务器高防CDN请联系玥玥", url='https://t.me/CDNYUEYUE')
|
||||
],
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="CK资源采集", url='https://ckzy1.com/')
|
||||
],
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="♻️CMS导航网♻️", url='https://t.me/maccms_jccms')
|
||||
],
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="💰流量变现💰", url='https://t.me/taohaozhan')
|
||||
],
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="🙎♂️代实名🙍♀️过人脸🅾️国际阿里云腾讯云(赞助商)", url='https://t.me/gjgzs2022')
|
||||
],
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="倩倩CDN服务器", url='https://t.me/KLT_12'),
|
||||
types.InlineKeyboardButton(
|
||||
text="💎DigitalVirt(赞助商)", url='https://digitalvirt.com/aff.php?aff=154')
|
||||
],
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="论坛", url='https://bbs.midoks.me'),
|
||||
types.InlineKeyboardButton(
|
||||
text="搜索", url='https://bbs.midoks.me/search.php'),
|
||||
types.InlineKeyboardButton(
|
||||
text="@ME", url='tg://user?id=5568699210'),
|
||||
types.InlineKeyboardButton(
|
||||
text="100RMB/M", url='tg://user?id=5568699210')
|
||||
]
|
||||
]
|
||||
markup = types.InlineKeyboardMarkup(keyboard)
|
||||
|
||||
msg_notice = "由于在解决的问题的时候,不给信息,无法了解情况。以后不再群里回答技术问题。全部去论坛提问。在解决问题的过程中,可能需要面板信息,和SSH信息,如无法提供请不要提问。为了让群里都知晓。轮播一年!\n"
|
||||
msg_notice += "为了不打扰双方,私聊解决问题先转100U,否则无视!\n"
|
||||
msg = bot.send_message(chat_id, msg_notice, reply_markup=markup)
|
||||
|
||||
# print(msg.message_id)
|
||||
time.sleep(90)
|
||||
try:
|
||||
bot.delete_message(
|
||||
chat_id=chat_id, message_id=msg.message_id)
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
|
||||
def run(bot):
|
||||
try:
|
||||
send_msg(bot, 'notice_msg', 180)
|
||||
except Exception as e:
|
||||
writeLog('-----push_notice_msg error start -------')
|
||||
print(mw.getTracebackInfo())
|
||||
writeLog('-----push_notice_msg error start -------')
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
push_*.py 识别为推送插件
|
||||
@@ -0,0 +1,220 @@
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
import base64
|
||||
import threading
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
import telebot
|
||||
from telebot import types
|
||||
from telebot.util import quick_markup
|
||||
|
||||
|
||||
def isThisCmd(cmd, msg):
|
||||
clen = len(cmd)
|
||||
msg_len = len(msg)
|
||||
if msg_len < clen:
|
||||
return False
|
||||
|
||||
check_msg = msg[0:clen]
|
||||
if cmd == check_msg:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def getReadCmd(cmd, msg):
|
||||
clen = len(cmd)
|
||||
msg_len = len(msg)
|
||||
real_msg = msg[clen:]
|
||||
return real_msg
|
||||
|
||||
|
||||
def getFaqKw(cmd):
|
||||
matchObj = re.match(r'寻找【(.*?)】问题如下', cmd, re.M | re.I)
|
||||
data = matchObj.groups()
|
||||
if len(data) > 0:
|
||||
return True, data[0]
|
||||
return False, ''
|
||||
|
||||
|
||||
def searchHttpPage(kw='', p=1, size=1):
|
||||
import urllib
|
||||
kw = kw.strip()
|
||||
kw = urllib.parse.quote_plus(kw)
|
||||
|
||||
api = 'https://bbs.midoks.me/plugin.php?id=external_api&f=bbs_search&q=' + kw + \
|
||||
'&size=' + str(size) + '&p=' + str(p)
|
||||
|
||||
# print('url', api)
|
||||
data = mw.httpGet(api)
|
||||
# print(data)
|
||||
data = json.loads(data)
|
||||
# print(data)
|
||||
if data['code'] > -1:
|
||||
|
||||
alist = data['data']['list']
|
||||
r = []
|
||||
for x in alist:
|
||||
tmp = {}
|
||||
tmp['tid'] = x['tid']
|
||||
tmp['subject'] = x['subject']
|
||||
tmp['url'] = 'https://bbs.midoks.me/thread-' + \
|
||||
x['tid'] + '-1-1.html'
|
||||
r.append(tmp)
|
||||
data['data']['list'] = r
|
||||
return data
|
||||
|
||||
|
||||
def searchFaq(bot, message, cmd_text):
|
||||
# cmd_text = 'mw'
|
||||
data = searchHttpPage(cmd_text, 1, 5)
|
||||
if data['code'] == 0 and len(data['data']['list']) > 0:
|
||||
keyboard = []
|
||||
|
||||
dlist = data['data']['list']
|
||||
for x in dlist:
|
||||
keyboard.append([types.InlineKeyboardButton(
|
||||
text=x['subject'], url=x['url'])])
|
||||
|
||||
keyboard.append([
|
||||
types.InlineKeyboardButton(
|
||||
text="下一页", callback_data='bbs_next_page_2'),
|
||||
types.InlineKeyboardButton(
|
||||
text="第" + str(data['data']['p']) + "页,共" + str(data['data']['page_num']) + "页", callback_data='bbs_page_total')
|
||||
])
|
||||
|
||||
keyboard.append([types.InlineKeyboardButton(
|
||||
text="关闭消息", callback_data='bbs_search_close')])
|
||||
|
||||
# print(keyboard)
|
||||
markup = types.InlineKeyboardMarkup(keyboard)
|
||||
bot.send_message(message.chat.id, "寻找【" +
|
||||
cmd_text.strip() + "】问题如下:", reply_markup=markup)
|
||||
else:
|
||||
keyboard = [
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="论坛", url='https://bbs.midoks.me'),
|
||||
types.InlineKeyboardButton(
|
||||
text="搜索", url='https://bbs.midoks.me/search.php')
|
||||
],
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="关闭消息", callback_data='bbs_search_close')
|
||||
]
|
||||
|
||||
]
|
||||
markup = types.InlineKeyboardMarkup(keyboard)
|
||||
bot.send_message(
|
||||
message.chat.id, "未找到合适内容,请在官方论坛[bbs.midoks.me]提问!", reply_markup=markup)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def searchDebug(bot, message, cmd_text):
|
||||
searchFaq(bot, message, cmd_text)
|
||||
return True
|
||||
|
||||
|
||||
def answer_callback_query(bot, call):
|
||||
|
||||
keyword = call.data
|
||||
|
||||
if keyword == 'bbs_search_close':
|
||||
bot.delete_message(chat_id=call.message.chat.id,
|
||||
message_id=call.message.message_id)
|
||||
return
|
||||
|
||||
is_bbs_page = False
|
||||
p = 1
|
||||
if keyword.startswith('bbs_next_page'):
|
||||
is_bbs_page = True
|
||||
p = keyword.replace('bbs_next_page_', '')
|
||||
|
||||
if keyword.startswith('bbs_pre_page'):
|
||||
is_bbs_page = True
|
||||
p = keyword.replace('bbs_pre_page_', '')
|
||||
|
||||
# print("p", p)
|
||||
if is_bbs_page:
|
||||
is_match, cmd_text = getFaqKw(call.message.text)
|
||||
if not is_match:
|
||||
bot.edit_message_text(
|
||||
chat_id=call.message.chat.id, message_id=call.message.message_id, text="出现错误!")
|
||||
return
|
||||
|
||||
data = searchHttpPage(cmd_text, int(p), 5)
|
||||
|
||||
dlist = data['data']['list']
|
||||
# print(data)
|
||||
keyboard = []
|
||||
for x in dlist:
|
||||
keyboard.append([types.InlineKeyboardButton(
|
||||
text=x['subject'], url=x['url'])])
|
||||
|
||||
page_nav = []
|
||||
if int(data['data']['p']) > 1:
|
||||
page_nav.append(types.InlineKeyboardButton(
|
||||
text="上一页", callback_data='bbs_pre_page_' + str(int(p) - 1)))
|
||||
|
||||
if data['data']['page_num'] != data['data']['p']:
|
||||
page_nav.append(types.InlineKeyboardButton(
|
||||
text="下一页", callback_data='bbs_next_page_' + str(int(p) + 1)))
|
||||
|
||||
page_nav.append(types.InlineKeyboardButton(
|
||||
text="第" + str(data['data']['p']) + "页,共" + str(data['data']['page_num']) + "页", callback_data='bbs_page_total'))
|
||||
|
||||
keyboard.append(page_nav)
|
||||
|
||||
keyboard.append([types.InlineKeyboardButton(
|
||||
text="关闭消息", callback_data='bbs_search_close')])
|
||||
|
||||
markup = types.InlineKeyboardMarkup(keyboard)
|
||||
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
|
||||
text=call.message.text, reply_markup=markup)
|
||||
|
||||
|
||||
def run(bot, message):
|
||||
text_body = message.text
|
||||
|
||||
# 过滤URL
|
||||
is_has_url = re.search(
|
||||
'(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]', text_body)
|
||||
if is_has_url:
|
||||
return bot
|
||||
|
||||
# print(text_body)
|
||||
if isThisCmd('/faq:', text_body):
|
||||
cmd_text = getReadCmd('/faq:', text_body)
|
||||
return searchFaq(bot, message, cmd_text)
|
||||
|
||||
# if isThisCmd('/debug', text_body):
|
||||
# cmd_text = getReadCmd('/debug', text_body)
|
||||
# return searchDebug(bot, message, cmd_text)
|
||||
|
||||
if text_body.find('?') > -1 or text_body.find('?') > -1:
|
||||
return_msg = "你似乎在寻找【" + text_body + "】答案:\n"
|
||||
return_msg += "/faq:开始寻找你的问题\n"
|
||||
keyboard = [
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="如未找到,可以在论坛补充你的提问!", url='https://bbs.midoks.me'),
|
||||
]
|
||||
|
||||
]
|
||||
markup = types.InlineKeyboardMarkup(keyboard)
|
||||
bot.reply_to(message, return_msg, reply_markup=markup)
|
||||
|
||||
return bot
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# print(isThisCmd('/?:', '/?:如何在安装面板'))
|
||||
# print(getReadCmd('/?:', '/?:如何在安装面板'))
|
||||
# print(searchHttpPage('mw'))
|
||||
print(getFaqKw('寻找【mw】问题如下:'))
|
||||
@@ -0,0 +1,87 @@
|
||||
# coding:utf-8
|
||||
|
||||
|
||||
# python /Users/midoks/Desktop/mwdev/server/tgclient/tgclient.py
|
||||
|
||||
from telethon import TelegramClient
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
sys.path.append(getServerDir() + "/extend")
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'tgclient'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getConfigData():
|
||||
cfg_path = getServerDir() + "/data.cfg"
|
||||
if not os.path.exists(cfg_path):
|
||||
mw.writeFile(cfg_path, '{}')
|
||||
t = mw.readFile(cfg_path)
|
||||
return json.loads(t)
|
||||
|
||||
|
||||
def writeConf(data):
|
||||
cfg_path = getServerDir() + "/data.cfg"
|
||||
mw.writeFile(cfg_path, json.dumps(data))
|
||||
return True
|
||||
|
||||
|
||||
def getExtCfg():
|
||||
cfg_path = getServerDir() + "/extend.cfg"
|
||||
if not os.path.exists(cfg_path):
|
||||
mw.writeFile(cfg_path, '{}')
|
||||
t = mw.readFile(cfg_path)
|
||||
return json.loads(t)
|
||||
|
||||
|
||||
def getStartExtCfgByTag(tag='push'):
|
||||
# 获取开启的扩展
|
||||
elist = getExtCfg()
|
||||
rlist = []
|
||||
for x in elist:
|
||||
if x['tag'] == tag and x['status'] == 'start':
|
||||
rlist.append(x)
|
||||
return rlist
|
||||
|
||||
|
||||
def writeLog(log_str):
|
||||
if __name__ == "__main__":
|
||||
print(log_str)
|
||||
|
||||
now = mw.getDateFromNow()
|
||||
log_file = getServerDir() + '/task.log'
|
||||
mw.writeFileLog(now + ':' + log_str, log_file, limit_size=5 * 1024)
|
||||
return True
|
||||
|
||||
|
||||
# start tgbot
|
||||
cfg = getConfigData()
|
||||
while True:
|
||||
cfg = getConfigData()
|
||||
if 'bot' in cfg and 'app_id' in cfg['bot']:
|
||||
if cfg['bot']['app_id'] != '' and cfg['bot']['app_id'] != 'app_id':
|
||||
break
|
||||
if cfg['bot']['app_hash'] != '' and cfg['bot']['app_hash'] != 'app_hash':
|
||||
break
|
||||
writeLog('等待输入配置,填写app_token')
|
||||
time.sleep(3)
|
||||
|
||||
client = TelegramClient('mdioks', cfg['bot']['api_id'], cfg['bot']['api_hash'])
|
||||
|
||||
async def main():
|
||||
# Now you can use all client methods listed below, like for example...
|
||||
await client.send_message('me', 'Hello to myself!')
|
||||
|
||||
with client:
|
||||
client.loop.run_until_complete(main())
|
||||
Reference in New Issue
Block a user