first
This commit is contained in:
parent
6983cf28c8
commit
dcca00c4a1
5
.gitignore
vendored
5
.gitignore
vendored
@ -150,5 +150,8 @@ cython_debug/
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
.idea/
|
||||
|
||||
# data
|
||||
config.ini
|
||||
*.session
|
||||
|
21
ci.py
Normal file
21
ci.py
Normal file
@ -0,0 +1,21 @@
|
||||
from configparser import RawConfigParser
|
||||
from httpx import get
|
||||
from pyrogram import Client
|
||||
|
||||
config = RawConfigParser()
|
||||
config.read("config.ini")
|
||||
bot_token: str = ""
|
||||
bot_token = config.get("basic", "bot_token", fallback=bot_token)
|
||||
|
||||
|
||||
# 自定义类型
|
||||
class Bot:
|
||||
def __init__(self, data: dict):
|
||||
self.uid = data["id"]
|
||||
self.username = data["username"]
|
||||
self.name = data["first_name"]
|
||||
|
||||
|
||||
me = Bot(get(f"https://api.telegram.org/bot{bot_token}/getme").json()["result"])
|
||||
# 初始化客户端
|
||||
app = Client("bot", bot_token=bot_token)
|
14
config.ini.example
Normal file
14
config.ini.example
Normal file
@ -0,0 +1,14 @@
|
||||
[pyrogram]
|
||||
api_id = 12345
|
||||
api_hash = 0123456789abc0123456789abc
|
||||
|
||||
[basic]
|
||||
bot_token = 111:abc
|
||||
|
||||
[plugins]
|
||||
root = plugins
|
||||
|
||||
[proxy]
|
||||
enabled = False
|
||||
hostname = 127.0.0.1
|
||||
port = 1080
|
44
defs/find.py
Normal file
44
defs/find.py
Normal file
@ -0,0 +1,44 @@
|
||||
import csv
|
||||
from os import sep
|
||||
from typing import List
|
||||
|
||||
handbook = {}
|
||||
handbook_max = 15
|
||||
|
||||
|
||||
class HandBook:
|
||||
def __init__(self, uid: str, name: str):
|
||||
self.uid = uid
|
||||
self.name = name
|
||||
|
||||
|
||||
with open(f"resources{sep}Handbook_CHS.csv", "r", encoding="utf-8") as f:
|
||||
reader = csv.reader(f)
|
||||
for row in reader:
|
||||
if row[0] == "":
|
||||
continue
|
||||
handbook[row[0]] = HandBook(row[0], row[1])
|
||||
|
||||
|
||||
def find(words: List) -> List[HandBook]:
|
||||
"""search a word in the handbook.
|
||||
|
||||
Args:
|
||||
words: The words to find.
|
||||
|
||||
Returns:
|
||||
A list of definitions.
|
||||
"""
|
||||
data, count = [], 0
|
||||
for key, value in handbook.items():
|
||||
add = False
|
||||
for word in words:
|
||||
if word.lower() in value.name.lower():
|
||||
add = True
|
||||
break
|
||||
if add:
|
||||
data.append(value)
|
||||
count += 1
|
||||
if count == handbook_max:
|
||||
break
|
||||
return data
|
11
main.py
Normal file
11
main.py
Normal file
@ -0,0 +1,11 @@
|
||||
import logging
|
||||
from pyrogram import idle
|
||||
from ci import app
|
||||
|
||||
# 日志记录
|
||||
logging.basicConfig(level=logging.ERROR)
|
||||
app.start()
|
||||
print("[INFO] 开始运行")
|
||||
idle()
|
||||
app.stop()
|
||||
print("[INFO] 结束运行")
|
22
plugins/find.py
Normal file
22
plugins/find.py
Normal file
@ -0,0 +1,22 @@
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
from defs.find import find
|
||||
from ci import me
|
||||
|
||||
|
||||
@Client.on_message(filters.incoming &
|
||||
filters.command(["find", f"find@{me.username}"]))
|
||||
async def find_thing(_: Client, message: Message):
|
||||
if len(message.command) == 1:
|
||||
await message.reply_text(
|
||||
"Please specify what you want to find."
|
||||
)
|
||||
else:
|
||||
data = find(message.command[1:])
|
||||
if data:
|
||||
text = f"关键词 <b>{' '.join(message.command[1:])}</b> 搜索到了:\n"
|
||||
for i in data:
|
||||
text += f" - <code>{i.uid}</code> - <b>{i.name}</b>\n"
|
||||
await message.reply_text(text)
|
||||
else:
|
||||
await message.reply_text("此关键词没有搜索到结果。")
|
24
plugins/help.py
Normal file
24
plugins/help.py
Normal file
@ -0,0 +1,24 @@
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from ci import me
|
||||
|
||||
help_msg = """
|
||||
<b>Grasscutters</b>
|
||||
|
||||
👩🏻💼 » /find <名称> - 查找物品/角色对应的 id <只显示前五个匹配项>
|
||||
<code>/find 枫原万叶</code>
|
||||
<code>/find 枫原万叶的命座</code>
|
||||
"""
|
||||
|
||||
|
||||
@Client.on_message(filters.incoming &
|
||||
filters.command(["help", f"help@{me.username}"]))
|
||||
async def help_command(_: Client, message: Message):
|
||||
await message.reply(
|
||||
help_msg,
|
||||
reply_markup=InlineKeyboardMarkup(
|
||||
[[InlineKeyboardButton("GitHub", url="https://github.com/Grasscutters/Grasscutter")]]
|
||||
),
|
||||
disable_web_page_preview=True,
|
||||
quote=True,
|
||||
)
|
8
plugins/ping.py
Normal file
8
plugins/ping.py
Normal file
@ -0,0 +1,8 @@
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
|
||||
@Client.on_message(filters.incoming & filters.private &
|
||||
filters.command(["ping", ]))
|
||||
async def ping_check(_: Client, message: Message):
|
||||
await message.reply("poi ~", quote=True)
|
27
plugins/start.py
Normal file
27
plugins/start.py
Normal file
@ -0,0 +1,27 @@
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from ci import me
|
||||
|
||||
des = """
|
||||
你好!{} 我是 [{}]({}),一个为 Grasscutter CN 用户打造的机器人!
|
||||
|
||||
加入 [我的频道](https://t.me/Grasscutter_CN)
|
||||
"""
|
||||
|
||||
|
||||
def gen_help_button() -> InlineKeyboardMarkup:
|
||||
data_ = [[InlineKeyboardButton("📢 官方频道", url="https://t.me/Grasscutter_CN")]]
|
||||
return InlineKeyboardMarkup(data_)
|
||||
|
||||
|
||||
@Client.on_message(filters.incoming & filters.private &
|
||||
filters.command(["start"]))
|
||||
async def start_command(_: Client, message: Message):
|
||||
"""
|
||||
回应消息
|
||||
"""
|
||||
await message.reply(des.format(message.from_user.mention(),
|
||||
me.name,
|
||||
f"https://t.me/{me.username}"),
|
||||
reply_markup=gen_help_button(),
|
||||
quote=True, )
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
pyrogram==1.4.16
|
||||
tgcrypto
|
||||
httpx
|
11402
resources/Handbook_CHS.csv
Normal file
11402
resources/Handbook_CHS.csv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user