Skip to content

Commit

Permalink
Merge pull request #12 from Valorant-Shop-CN/develop
Browse files Browse the repository at this point in the history
chowm(1.1.5): release v1.1.5
  • Loading branch information
musnows committed May 5, 2023
2 parents b9916c6 + c5e3a90 commit 4fd27b6
Show file tree
Hide file tree
Showing 13 changed files with 1,186 additions and 266 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ __pycache__/
.vscode/

# webfile

!code/web/ahri/index.html
code/web/
51 changes: 28 additions & 23 deletions code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,33 @@ async def botmarket():

# 每5分钟保存一次文件
@bot.task.add_interval(minutes=5)
async def Save_File_Task():
async def save_file_task():
try:
await save_all_file()
except:
err_cur = f"ERR! [{getTime()}] [Save.File.Task]\n```\n{traceback.format_exc()}\n```"
_log.exception("ERR in Save_File_Task")
await bot.client.send(debug_ch, err_cur) # type: ignore


# `/kill @机器人` 下线bot
@bot.command(name='kill')
async def KillBot(msg: Message, num: str = '124124', *arg):
async def KillBot(msg: Message, at_text = '', *arg):
BotLog.logMsg(msg)
try:
if '-' in num or '.' in num:
return await msg.reply(f"参数num错误:{num}\n该参数应为bot的编号:{config['no']}")
if msg.author_id == master_id and int(num) == config['no']:
# 如果不是管理员直接退出,不要提示
if msg.author_id != master_id:
return
# 必须要at机器人,或者私聊机器人
cur_bot = await bot.client.fetch_me()
if f"(met){cur_bot.id}(met)" in at_text or isinstance(msg,PrivateMessage):
# 保存所有文件
await save_all_file(False)
await msg.reply(f"[KILL] 保存全局变量成功,bot下线")
res = await bot_offline() # 调用接口下线bot
_log.info(f"KILL | bot-off: {res}\n")
os._exit(0) # 退出程序
else:
await msg.reply(f"您没有权限或参数错误!\n本Bot编号为:{config['no']}")
_log.info(f"[kill] invalid kill = {msg.content}")
except:
await BotLog.BaseException_Handler("kill",traceback.format_exc(),msg)

Expand Down Expand Up @@ -123,7 +126,11 @@ async def atAhri(msg: Message):
# kook系统通知
if msg.author_id == "3900775823":
return
if f"(met){bot.client.me.id}(met)" in msg.content:
if len(msg.content) >= 22:
return
# 要求只是存粹at机器人的时候才恢复
cur_bot = await bot.client.fetch_me()
if f"(met){cur_bot.id}(met)" in msg.content:
BotLog.logMsg(msg)
if msg.author_id == master_id:
text = Help.help_develop()
Expand Down Expand Up @@ -494,23 +501,20 @@ async def login_list(msg:Message,*arg):
# 获取每日商店的命令
@bot.command(name='shop', aliases=['SHOP'])
async def get_daily_shop(msg: Message,index:str = "0",*arg):
BotLog.logMsg(msg)
if LoginForbidden:
await LoginForbidden_send(msg)
return
# index参数是下标,应该为一个正整数
elif "-" in index or "." in index:
await msg.reply(f"index 参数错误,请使用「/login-l」查看您需要查询的商店账户,并指定正确的编号(默认为0,即第一个账户)")
return
# 提前初始化变量
send_msg = {'msg_id':''}
send_msg = {'msg_id':''}# 提前初始化变量
resp = ""
cm = CardMessage()
try:
# 0.进行命令有效性判断
BotLog.logMsg(msg)
if LoginForbidden:
return await LoginForbidden_send(msg)
elif "-" in index or "." in index: # index参数是下标,应该为一个正整数
await msg.reply(f"index 参数错误,请使用「/login-l」查看您需要查询的商店账户,并指定正确的编号(默认为0,即第一个账户)")
return
# 1.如果用户不在Authdict里面,代表没有登录,直接退出
if msg.author_id not in UserAuthCache['kook']:
await msg.reply(await get_card_msg("您尚未登陆!请「私聊」使用login命令进行登录操作", f"「/login 账户 密码」请确认您知晓这是一个风险操作", icon_cm.whats_that))
return
return await msg.reply(await get_card_msg("您尚未登陆!请「私聊」使用login命令进行登录操作", f"「/login 账户 密码」请确认您知晓这是一个风险操作", icon_cm.whats_that))

# 2.判断下标是否合法,默认下标为0
_index = int(index)
Expand Down Expand Up @@ -585,7 +589,7 @@ async def get_daily_shop(msg: Message,index:str = "0",*arg):
vp=play_currency['vp'],
rp=play_currency['rp'],
bg_img_src=background_img)
else: # 5.1.3 普通用户
else:# 5.1.3 普通用户
# 判断是否有缓存命中
cache_ret = await ShopRate.query_ShopCache(skinlist=list_shop)
if not cache_ret['status']: # 缓存没有命中
Expand Down Expand Up @@ -647,8 +651,9 @@ async def get_daily_shop(msg: Message,index:str = "0",*arg):
err_str = f"ERR! [{getTime()}] shop\n```\n{traceback.format_exc()}\n```\n"
if "SkinsPanelLayout" in str(result):
_log.error(err_str + str(resp))
btext = f"KeyError:{result}, please re-login\n如果此问题重复出现,请[联系开发者](https://kook.top/gpbTwZ)"
cm = await get_card_msg(f"键值错误,需要重新登录", btext, icon_cm.whats_that)
b_text = f"KeyError:{result}, please re-login\n如果此问题重复出现,请[联系开发者](https://kook.top/gpbTwZ)\n"
b_text+= f"```\n{str(resp)}\n```" # 把api的返回值也发出去
cm = await get_card_msg(f"键值错误,需要重新登录", b_text, icon_cm.whats_that)
await upd_card(send_msg['msg_id'], cm, channel_type=msg.channel_type)
else:
await BotLog.BaseException_Handler("shop", traceback.format_exc(), msg, send_msg=send_msg)
Expand Down
9 changes: 5 additions & 4 deletions code/makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.PHONY:ps
ps:
ps jax | head -1 && ps jax | grep start.py | grep -v grep

.PHONY:run
run:
nohup python3.10 -u start.py >> /dev/null 2>&1 &
# 包含khl输出结果的信息里面会有用户的账户密码,重定向到黑洞,避免打印账户密码
.PHONY:ps
ps:
ps jax | head -1 && ps jax | grep start.py | grep -v grep
# 包含khl输出结果的信息里面会有用户的账户密码,重定向到黑洞,避免打印账户密码
10 changes: 5 additions & 5 deletions code/pkg/plugins/GrantRoles.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def thanks_sponser(bot: Bot, kook_header=kook_headers):
def init(bot:Bot,master_id:str):
"""master_id: bot master user_id"""
# 在不修改代码的前提下设置上色功能的服务器和监听消息
@bot.command(name='Color_Set_GM', case_sensitive=False)
@bot.command(name='Color-Set-GM', case_sensitive=False)
async def Color_Set_GM(msg: Message, Card_Msg_id: str):
BotLog.logMsg(msg)
if msg.author_id == master_id:
Expand All @@ -145,7 +145,7 @@ async def Color_Set(msg: Message):
await Color_SetMsg(bot, msg)


# 感谢助力者(每天19点进行检查)
@bot.task.add_cron(hour=19, minute=0, timezone="Asia/Shanghai")
async def thanks_sponser_task():
await thanks_sponser(bot)
# # 感谢助力者(每天19点进行检查)
# @bot.task.add_cron(hour=19, minute=0, timezone="Asia/Shanghai")
# async def thanks_sponser_task():
# await thanks_sponser(bot)
40 changes: 31 additions & 9 deletions code/pkg/plugins/StatusWeb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import copy
import time
import traceback
Expand All @@ -9,9 +10,29 @@

SHOW_DAYS = 31
"""显示最近多少天的数据"""
WEB_ROOT_PATH = "./web/ahri"
"""html文件的根路径,末尾不能带/"""
WEB_PAGE_PATH = ["gu","ngu"]
"""html页面文件的路径,末尾不能带/,不存在会创建"""

def create_web_path():
"""新建web路径"""
if (not os.path.exists(WEB_ROOT_PATH)):
os.makedirs(WEB_ROOT_PATH) # 文件夹不存在,创建
_log.info(f"[plugins] create web path {WEB_ROOT_PATH}")
for path in WEB_PAGE_PATH:
cur = f"{WEB_ROOT_PATH}/{path}"
if (not os.path.exists(cur)):
os.makedirs(cur) # 文件夹不存在,创建
_log.info(f"[plugins] create web path {path}")

def init(bot:Bot,master_id:str):
"""初始化之前,机器人会判断根路径是否存在,不在则创建文件夹
- bot:Bot
- master_id: admin user id
"""
create_web_path()

async def data_manamge(key:str)->list:
"""处理日志文件中,服务器/用户/命令的数据
Args(key):
Expand Down Expand Up @@ -46,16 +67,16 @@ async def data_manamge(key:str)->list:
# 没有相同日期的,才新建键值
if flag:
data_list.append({"date":date,"category":'user','num':1,'time':Gtime.getTimeStampFromStr(uinfo[key])})
# 如果是used_time,则还需要处理命令
# 如果是used_time,需要处理每日的命令/服务器/用户数量
elif key == 'used_time':
for d in BotUserDict['cmd']['data']:
for d in BotUserDict['cmd']['data']:# 命令
num = BotUserDict['cmd']['data'][d]
data_list.append({"date":d,"category":'command','num':num,'time':Gtime.getTimeStampFromStr(d)})
for d in BotUserDict['cmd']['user']:
num = BotUserDict['cmd']['user'][d]
for d in BotUserDict['cmd']['user']:# 用户
num = len(BotUserDict['cmd']['user'][d]) # 长度就是用户数量
data_list.append({"date":d,"category":'user','num':num,'time':Gtime.getTimeStampFromStr(d)})
for d in BotUserDict['cmd']['guild']:
num = BotUserDict['cmd']['guild'][d]
for d in BotUserDict['cmd']['guild']:# 服务器
num = len(BotUserDict['cmd']['guild'][d])
data_list.append({"date":d,"category":'guild','num':num,'time':Gtime.getTimeStampFromStr(d)})
# 依照日期排序
data_list = sorted(data_list,key=lambda kv: kv['date'])
Expand Down Expand Up @@ -91,7 +112,7 @@ async def render_ngu_web(exp_raise = False):
}
})
# 生成html文件
line.render("./web/ahri/ngu/index.html")
line.render(f"{WEB_ROOT_PATH}/ngu/index.html")
_log.info(f"render new guild/user status web")
except Exception as result:
_log.exception("Error occur")
Expand Down Expand Up @@ -126,7 +147,7 @@ async def render_guc_web(exp_raise = False):
}
})
# 生成html文件
line.render("./web/ahri/gu/index.html")
line.render(f"{WEB_ROOT_PATH}/gu/index.html")
_log.info(f"render guild/user/cmd status web")
except Exception as result:
_log.exception("Error occur")
Expand All @@ -153,4 +174,5 @@ async def update_web_cmd(msg:Message):
await msg.reply(f"网页更新成功")
except:
await msg.reply(f"网页渲染出现错误\n```\n{traceback.format_exc()}```\n")


_log.info("[plugins] load StatusWeb.py")
2 changes: 1 addition & 1 deletion code/pkg/plugins/Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def TLCheck(msg: Message):


# 关闭所有栏位的实时翻译(避免有些人用完不关)
@bot.command(name='ShutdownTL', aliases=['TLSD','tlsd'])
@bot.command(name='ShutdownTL', aliases=['tlsd'],case_sensitive=False)
async def TLShutdown(msg: Message):
BotLog.logMsg(msg)
if msg.author.id != master_id:
Expand Down
42 changes: 24 additions & 18 deletions code/pkg/utils/Help.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def help_main(start_time: str):
Module.Context(
Element.Text(f"开源代码见[Github](https://github.com/Valorant-Shop-CN/Kook-Valorant-Bot),开机于 [{start_time}]",
Types.Text.KMD)))
c3.append(Module.Section('图文版帮助命令', Element.Button('点我', 'https://blog.musnow.top/posts/847195815/?utm_source=kook', Types.Click.LINK,theme=Types.Theme.PRIMARY)))
c3.append(Module.Section('图文版帮助命令和机器人使用文档', Element.Button('点我', 'https://blog.musnow.top/posts/847195815/?utm_source=kook', Types.Click.LINK,theme=Types.Theme.PRIMARY)))
c3.append(Module.Divider())
# c3.append(Module.Section('「/hello」来和本狸打个招呼吧!\n「/Ahri」 帮助指令\n'))
# c3.append(Module.Divider())
c3.append(Module.Header('上号,瓦一把!'))
Expand All @@ -23,9 +24,9 @@ def help_main(start_time: str):
c3.append(Module.Header('和阿狸玩小游戏吧~ '))
text = "「/roll 1 100」掷骰子1-100,范围可自主调节。可在末尾添加第三个参数实现同时掷多个骰子\n"
text += "「/countdown 秒数」倒计时,默认60秒\n"
text += "「/TL 内容」翻译内容,支持多语译中和中译英\n"
text += "「/TLON」 在本频道打开实时翻译\n"
text += "「/TLOFF」在本频道关闭实时翻译\n"
text += "「/tl 内容」翻译内容,支持多语译中和中译英\n"
text += "「/tlon」 在本频道打开实时翻译\n"
text += "「/tloff」在本频道关闭实时翻译\n"
text += "「/we 城市」查询城市未来3天的天气情况\n"
# text += "「更多…」还有一些隐藏指令哦~\n"
c3.append(Module.Section(Element.Text(text, Types.Text.KMD)))
Expand All @@ -41,13 +42,14 @@ def help_val():
Module.Header('目前阿狸支持查询的valorant信息如下'),
Module.Context(
Element.Text("开源代码见[Github](https://github.com/Valorant-Shop-CN/Kook-Valorant-Bot),更多查询功能上线中...", Types.Text.KMD)))
c3.append(Module.Section('图文版帮助命令', Element.Button('点我', 'https://blog.musnow.top/posts/847195815/?utm_source=kook', Types.Click.LINK,theme=Types.Theme.PRIMARY)))
text = "使用前,请确认您知晓相关功能可能有风险:\n"
text += "1.阿狸的后台不会做任何`打印`您的游戏账户密码的操作,若在使用相关功能后被盗号,阿狸可不承担任何责任;\n"
text += "2.如果您发现登陆后阿狸还提醒您没有登录,那是因为阿狸的作者正在调试阿狸,重启后登录信息会消失。感谢谅解;\n"
text += "3.目前查询功能稳定性尚可,但无法排除`封号`风险;\n"
text += "4.指定save后,账户密码是存在全局变量(内存)中的,并不会存到硬盘里面。只要bot下线(进程退出)就会被清除;\n"
text += "若担心相关风险,请不要使用如下功能\n"
c3.append(Module.Section('图文版帮助命令和机器人使用文档', Element.Button('点我', 'https://blog.musnow.top/posts/847195815/?utm_source=kook', Types.Click.LINK,theme=Types.Theme.PRIMARY)))
c3.append(Module.Divider())
text = "使用前,请确认您知晓相关功能可能有风险,详见图文版帮助命令-免责声明\n"
# text += "1.阿狸的后台不会做任何`打印`您的游戏账户密码的操作,若在使用相关功能后被盗号,阿狸可不承担任何责任;\n"
# text += "2.如果您发现登陆后阿狸还提醒您没有登录,那是因为阿狸的作者正在调试阿狸,重启后登录信息会消失。感谢谅解;\n"
# text += "3.目前查询功能稳定性尚可,但无法排除`封号`风险;\n"
# text += "4.指定save后,账户密码是存在全局变量(内存)中的,并不会存到硬盘里面。只要bot下线(进程退出)就会被清除;\n"
# text += "若担心相关风险,请不要使用如下功能\n"
c3.append(Module.Section(Element.Text(text, Types.Text.KMD)))
c3.append(Module.Divider())
help_1 = "「/bundle 皮肤名」 查询皮肤系列包含什么枪械\n"
Expand All @@ -71,11 +73,11 @@ def help_val():
c3.append(Module.Header("以下进阶功能,发电支持阿狸即可解锁哦~"))
help_2 = "「/vip-u 激活码」兑换阿狸的vip\n"
help_2 += "「/vip-c」 查看vip的剩余时间\n"
help_2 += "「全新商店展示图」vip用户将获取到16-9的超帅商店返回值\n"
help_2 += "「/vip-shop」查看已保存的商店查询diy背景图\n"
help_2 += "「/vip-shop 图片url」添加商店查询diy背景图\n"
help_2 += "「/vip-shop-s 图片编号」切换商店查询的背景图\n"
help_2 += "「保存登录信息」vip用户登陆后,阿狸会自动保存您的cookie。在阿狸维护重启的时候,您的登录信息不会丢失\n"
help_2 += "「全新商店展示图」vip用户将获取到16-9的超帅商店返回值\n"
help_2 += "「登录信息缓存」vip用户登陆后,阿狸会自动保存您的cookie。在阿狸维护重启的时候,您的登录信息不会丢失\n"
help_2 += "「早八商店提醒」阿狸将在早8点获取vip用户的每日商店并私聊发图给用户。同时会对这张图片进行缓存,当天使用`/shop`命令的时候,只需2s获取结果,三倍于普通用户的响应速度!\n\n"
help_2 += "1.目前商店查询diy背景图支持16-9(横屏)的图片,图片url获取:PC端将图片上传到kook→点击图片→底部`...`处复制图片链接→使用`/vip-shop`命令设置背景 [教程图](https://img.kookapp.cn/assets/2022-12/nICYcewY8a0u00yt.png)\n"
help_2 += "2.请不要设置违规图片(擦边也不行)!若因为您上传违禁图片后导致阿狸被封,您将被剥夺vip并永久禁止兑换vip\n"
Expand All @@ -90,21 +92,25 @@ def help_val():


def help_develop():
c = Card(Module.Header("主人有何吩咐呀~"),Module.Divider())
text = f"主人有何吩咐呀~\n```\n"
text += f"[/Color_Set] 发送一个用于设置用户颜色的消息,只能在valorant社区使用\n"
text += f"[/Color_Set_GM 消息id] 在不修改代码的前提下设置上色功能的服务器和监听消息\n"
text += f"[/ShutdownTL] 关闭所有实时翻译的栏位\n"
text += f"[/color-set] 发送一个用于设置用户颜色的消息,只能在valorant社区使用\n"
text += f"[/color-set-gm 消息id] 在不修改代码的前提下设置上色功能的服务器和监听消息\n"
text += f"[/tlsd] 关闭所有实时翻译的栏位\n"
text += f"[/vip-a 天数 数量] 生成新的vip激活码\n"
text += f"[/vip-l] 查看当前vip用户列表\n"
text += f"[/vip-img] 检查vip用户的自定义背景图(防止违规图片)\n"
text += f"[/vip-r 天数 数量 抽奖天数] 开启vip抽奖\n"
text += f"[/vip-ta 天数] 给所有vip用户添加时长\n"
text += f"[/ckau] 查看已登录的用户个数\n"
text += f"[/upd] 手动更新商店物品和价格\n"
text += f"[/upd-web] 手动更新阿狸使用日志网页\n"
text += f"[/open-nm] 打开/关闭夜市\n"
text += f"[/ban-r 用户id] 禁止用户使用rate相关功能\n"
text += f"[/notify-test] 执行遍历用户皮肤notify列表\n"
text += f"[/lf] 实际上是LoginForbidden的缩写,在login函数403时屏蔽所有需要login的命令\n"
text += f"[/log] 显示当前阿狸加入的服务器以及用户数量\n"
text += f"[/mem] 显示当前阿狸进程的内存占用和cpu占用\n```"
return text
text += f"[/mem] 显示当前阿狸进程的内存占用和cpu占用\n"
text += f"[/kill @bot] 下线机器人\n```"
c.append(Module.Section(Element.Text(text,Types.Text.KMD)))
return CardMessage(c)
Loading

0 comments on commit 4fd27b6

Please sign in to comment.