-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
237 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import time | ||
|
||
from nonebot import on_command, CommandSession, permission | ||
|
||
from ...xlog import xlogger | ||
from xunbot import get_bot | ||
|
||
Bot = get_bot() | ||
|
||
CALL_BLACK_DICT = Bot.config.CALL_BLACK_DICT | ||
SUPERUSERS = Bot.config.SUPERUSERS | ||
|
||
__plugin_name__ = '致电管理员' | ||
__plugin_usage__ = r""" | ||
让小寻帮忙致电管理员 | ||
*请不要发无意义的内容* | ||
call_admin [致电内容] | ||
致电管理员 [内容] | ||
eg. | ||
call_admin 小寻XX功能失效了 | ||
致电管理员 希望加入XX功能 | ||
""".strip() | ||
|
||
|
||
@on_command('call_admin', aliases=('call_admin', '致电管理员', '致電管理員'), permission=Bot.level) | ||
async def call_admin(session: CommandSession): | ||
id = session.event['user_id'] | ||
|
||
if id not in CALL_BLACK_DICT: | ||
info = session.get('info', prompt='给我你需要致电的信息') | ||
xlogger.info("Get Information: {} \nfrom ID: {}".format(info, id)) | ||
|
||
if SUPERUSERS: | ||
sender_info = "\n——@{}({}) | {}".format(session.event['sender']['nickname'], id, | ||
time.strftime("%Y-%m-%d", time.localtime(session.event['time']))) | ||
|
||
for admin in SUPERUSERS: | ||
await Bot.send_private_msg(user_id=admin, message="您有一条致电的信息:") | ||
await Bot.send_private_msg(user_id=admin, message=info + sender_info) | ||
await session.send("致电成功:)") | ||
xlogger.info("Successful call admin") | ||
else: | ||
await session.send("……管理员鸽了,知道管理员在哪儿摸鱼的话请把他拖回来~") | ||
else: | ||
xlogger.info("ID: {} wanna call admin, but in blacklist".format(id)) | ||
await session.send("致电失败:)\n您已被列入黑名单,无法致电") | ||
|
||
|
||
@call_admin.args_parser | ||
async def _(session: CommandSession): | ||
arg = session.current_arg | ||
|
||
if session.is_first_run: | ||
if arg: | ||
session.state['info'] = arg | ||
return | ||
|
||
if not arg: | ||
session.pause('管理员让我给宁带个话:宁搁这儿虚空致电呢?GKD把信息给我!') | ||
|
||
session.state[session.current_key] = arg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
ps.无参数时,返回功能列表 | ||
eg. | ||
help [无参数] #返回功能列表 | ||
help [功能名称] | ||
help 使用帮助 | ||
""".strip() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import time | ||
|
||
from nonebot import on_command, CommandSession, permission | ||
|
||
from .data_source import get_msg_from_board, save_msg_board | ||
from ...xlog import xlogger | ||
from xunbot import get_bot | ||
|
||
Bot = get_bot() | ||
MAX_MGB_WORD = Bot.config.MAX_MGB_WORD | ||
MAX_MGB_LIST = Bot.config.MAX_MGB_LIST | ||
|
||
|
||
__plugin_name__ = '留言板' | ||
__plugin_usage__ = r""" | ||
在留言板上进行留言或者查看留言 | ||
注意留言字数不要超过{}字 | ||
最多查看最后{}条留言 | ||
mgb [留言] | ||
留言板 [留言] | ||
ps.无参数时,为查看留言 | ||
eg. | ||
mgb sk是屑的天花板 | ||
留言板 skwlp | ||
mgb #查看留言 | ||
""".format(MAX_MGB_WORD,MAX_MGB_LIST).strip() | ||
|
||
|
||
@on_command('message_board', aliases=('mgb', '留言板'), permission=Bot.level) | ||
async def message_board(session: CommandSession): | ||
msg = session.current_arg_text.strip() | ||
if msg: | ||
if len(msg) <= MAX_MGB_WORD: | ||
save_msg_board(session.event['sender'], msg, session.event['time']) | ||
await session.send("留言成功:)") | ||
else: | ||
await session.send("留言失败:(\n超过字数限制,请不要超过{}字。".format(MAX_MGB_WORD)) | ||
else: | ||
message_board_report = await get_msg_from_board(MAX_MGB_LIST) | ||
await session.send(message_board_report) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import time | ||
from os import path, getcwd | ||
|
||
import pandas as pd | ||
|
||
from ...xlog import xlogger | ||
|
||
|
||
async def get_msg_from_board(num: int) -> str: | ||
try: | ||
all_msg = load_msg_board() | ||
except FileNotFoundError as e: | ||
return "暂时没有留言" | ||
|
||
line_list = ["{}\n——@{}({}) | {}".format( | ||
data['message'], data['nickname'], data['id'], | ||
time.strftime("%Y-%m-%d", time.localtime(data['time']))) | ||
for index, data in all_msg[-num:].iterrows()] | ||
|
||
return "\n\n".join(line_list) | ||
|
||
|
||
def load_msg_board() -> pd.DataFrame: | ||
all_msg = pd.read_csv(getcwd() + "\\msg_board.csv").sort_values(by='time') | ||
xlogger.info("Message board data read successfully") | ||
return all_msg | ||
|
||
|
||
def save_msg_board(sender: dict, msg: str, time: int): | ||
msg_board_f = open(getcwd() + '\\msg_board.csv', "a", encoding='utf-8') | ||
if not msg_board_f.tell(): | ||
msg_board_f.write("nickname,id,time,message" + "\n") | ||
|
||
info = "{},{},{},{}".format(sender['nickname'], sender['user_id'], time, msg) | ||
msg_board_f.write(info + "\n") | ||
xlogger.debug("Message board is written {}".format(info)) | ||
msg_board_f.close() | ||
xlogger.info("Message board saved successfully") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import time | ||
|
||
from nonebot import on_command, CommandSession, permission | ||
|
||
from ...xlog import xlogger | ||
from xunbot import get_bot | ||
|
||
Bot = get_bot() | ||
|
||
PUSH_GROUP_DICT = Bot.config.PUSH_GROUP_DICT | ||
|
||
__plugin_name__ = '群通知' | ||
__plugin_usage__ = r""" | ||
【管理员功能】 | ||
用于管理员通知群的功能 | ||
通知 【信息】 | ||
push 【信息】 | ||
""".strip() | ||
|
||
|
||
@on_command('notice', aliases=('push', '通知'), permission=0xF000) | ||
async def notice(session: CommandSession): | ||
info = session.get('info', prompt='请给出需要通知的信息') | ||
|
||
if PUSH_GROUP_DICT: | ||
header = "🔈群通知🔈\n\n" | ||
sender_info = "\n\n——{}(管理员) 发布于 {}".format(session.event['sender']['nickname'], | ||
time.strftime("%Y-%m-%d", time.localtime(session.event['time']))) | ||
|
||
for group in PUSH_GROUP_DICT: | ||
await Bot.send_group_msg(group_id=group, message=header + info + sender_info) | ||
await session.send("通知成功:)") | ||
else: | ||
await session.send("没有要通知的群,请注意修改config.py文件中对应值") | ||
|
||
|
||
@notice.args_parser | ||
async def _(session: CommandSession): | ||
arg = session.current_arg | ||
|
||
if session.is_first_run: | ||
if arg: | ||
session.state['info'] = arg | ||
return | ||
|
||
if not arg: | ||
session.pause('通知的信息不能为空,请重新输入') | ||
|
||
session.state[session.current_key] = arg |