Skip to content

Commit

Permalink
♻️ Reformat All Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jul 1, 2023
1 parent 4aa94e7 commit a7a3420
Show file tree
Hide file tree
Showing 108 changed files with 5,043 additions and 2,225 deletions.
14 changes: 9 additions & 5 deletions 1A2B/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ def check_answer(self, answer: str):
return a, b


@listener(command="1A2B",
groups_only=True,
description="Play a game of 1A2B",
parameters="[start/stop/answer]")
@listener(
command="1A2B",
groups_only=True,
description="Play a game of 1A2B",
parameters="[start/stop/answer]",
)
async def play_game_1a2b(message: Message):
if not message.arguments:
return await message.edit("Please specify a command.")
Expand All @@ -76,7 +78,9 @@ async def play_game_1a2b(message: Message):
try:
a, b = game.check_answer(message.arguments)
except ValueError:
return await message.edit("You need to guess 4 numbers between 0 ~ 9.\nFor example: 1234")
return await message.edit(
"You need to guess 4 numbers between 0 ~ 9.\nFor example: 1234"
)
if a == 4:
return await message.edit("You Win!\n\nGame over.")
return await message.edit("%d: %dA%dB" % (game.times, a, b))
2,161 changes: 1,883 additions & 278 deletions abstract/main.py

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions aff/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ def del_aff() -> None:
del sqlite["aff.web_page"]


@listener(command="aff",
description="在别人要打算买机场的时候光速发出自己的aff信息(请尽量配合短链接)",
parameters="[save|remove] (可选,回复一条消息,用于保存|删除aff信息)")
@listener(
command="aff",
description="在别人要打算买机场的时候光速发出自己的aff信息(请尽量配合短链接)",
parameters="[save|remove] (可选,回复一条消息,用于保存|删除aff信息)",
)
async def aff(message: Message):
if not message.parameter:
msg, web_page = get_aff()
Expand Down
16 changes: 10 additions & 6 deletions aireply/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def chats(self):
ai_setting = Setting("aireply")


@listener(command="aireply",
need_admin=True,
parameters="{on|off|add|del|list}",
description="通过预设根据语义分析进行应答,支持设置白名单并全局开关")
@listener(
command="aireply",
need_admin=True,
parameters="{on|off|add|del|list}",
description="通过预设根据语义分析进行应答,支持设置白名单并全局开关",
)
async def ai_reply(_: Client, message: Message):
input_str = message.arguments
chats = ai_setting.chats()
Expand Down Expand Up @@ -76,7 +78,7 @@ async def ai_reply(_: Client, message: Message):
text += f"• `{chatid}`\n"
await message.edit(text)
else:
await edit_delete(message, lang('arg_error'))
await edit_delete(message, lang("arg_error"))


@listener(incoming=True, outgoing=True, privates_only=True)
Expand All @@ -100,4 +102,6 @@ async def replay_listener(_, message: Message):
if reply != 0:
await asyncio.sleep(random.uniform(0, 1))
await bot.send_message(message.from_user.id, reply)
print(f"aireply: AI Reply to '{message.from_user.mention()}' by '{reply}'")
print(
f"aireply: AI Reply to '{message.from_user.mention()}' by '{reply}'"
)
28 changes: 18 additions & 10 deletions alicloud/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

class AliCloud:
def __init__(self):
self.url = 'https://api.aliyundrive.com/adrive/v1/timeline/homepage/list_message'
self.url = (
"https://api.aliyundrive.com/adrive/v1/timeline/homepage/list_message"
)
self.data = {
"user_id": "ec11691148db442aa7aa374ca707543c", # 阿里盘盘酱
"limit": 50,
Expand All @@ -27,8 +29,8 @@ def __init__(self):

@staticmethod
def parse_time(timestamp: int) -> str:
""" parse timestamp to date time """
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
"""parse timestamp to date time"""
return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")

async def get(self):
with contextlib.suppress(Exception):
Expand Down Expand Up @@ -59,8 +61,14 @@ def get_text(self, share_time=None, share_id=None) -> str:
share_time = self.share_time
if not share_id:
share_id = self.share_id
return (f"最近一次阿里云盘掉落福利的时间是 {self.parse_time(share_time)}\n\n"
f"https://www.aliyundrive.com/s/{share_id}") if share_id else "未获取到阿里云盘掉落福利信息"
return (
(
f"最近一次阿里云盘掉落福利的时间是 {self.parse_time(share_time)}\n\n"
f"https://www.aliyundrive.com/s/{share_id}"
)
if share_id
else "未获取到阿里云盘掉落福利信息"
)

async def send_to_chat(self, cid: int):
try:
Expand Down Expand Up @@ -94,15 +102,15 @@ async def alicloud_startup() -> None:
await alicloud.push()


@listener(command="alicloud",
description="获取阿里云盘掉落福利信息",
parameters="[订阅/退订]")
@listener(command="alicloud", description="获取阿里云盘掉落福利信息", parameters="[订阅/退订]")
async def set_alicloud_notice(message: Message):
if not message.arguments:
try:
item = await alicloud.get()
text = alicloud.get_text(item["created"] / 1000, item["content"]["share_id"])
except Exception as e: # noqa
text = alicloud.get_text(
item["created"] / 1000, item["content"]["share_id"]
)
except Exception as e: # noqa
text = f"获取阿里云盘掉落福利信息失败:{e}"
return await message.edit(text)
elif message.arguments == "订阅":
Expand Down
114 changes: 57 additions & 57 deletions alpha/auto_send_reactions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,29 @@
# 获取内容中的表情符号,并用|分割
def get_emoji(text):
if emojiArr := emoji.distinct_emoji_list(text):
delimiter = '|'
delimiter = "|"
return delimiter.join(emojiArr)
else:
return False


@listener(is_plugin=False,
outgoing=True,
command="auto_send_reactions",
description='\n自动回复Emoji插件',
parameters="`\n自动回复Emoji插件,支持同时设置多个目标生效用户,目前仅支持回复用户在群组中发送的消息,默认在所有已加入的群组中生效\n"
"\n**设置插件状态**:"
"\n启用:`,auto_send_reactions enable`"
"\n停用:`,auto_send_reactions disable`"
"\n\n**设置目标生效用户**:"
"\n添加:`,auto_send_reactions set <用户id/用户名> <表情内容>`"
"\n移除:`,auto_send_reactions unset <用户id/用户名>`"
"\n支持直接回复消息以进行快速设置,可以省略用户标识参数"
"\n\n**设置生效群组黑名单**:"
"\n添加:`,auto_send_reactions block <群组id/群组用户名>`"
"\n移除:`,auto_send_reactions unblock <群组id/群组用户名>\n")
@listener(
is_plugin=False,
outgoing=True,
command="auto_send_reactions",
description="\n自动回复Emoji插件",
parameters="`\n自动回复Emoji插件,支持同时设置多个目标生效用户,目前仅支持回复用户在群组中发送的消息,默认在所有已加入的群组中生效\n"
"\n**设置插件状态**:"
"\n启用:`,auto_send_reactions enable`"
"\n停用:`,auto_send_reactions disable`"
"\n\n**设置目标生效用户**:"
"\n添加:`,auto_send_reactions set <用户id/用户名> <表情内容>`"
"\n移除:`,auto_send_reactions unset <用户id/用户名>`"
"\n支持直接回复消息以进行快速设置,可以省略用户标识参数"
"\n\n**设置生效群组黑名单**:"
"\n添加:`,auto_send_reactions block <群组id/群组用户名>`"
"\n移除:`,auto_send_reactions unblock <群组id/群组用户名>\n",
)
async def AutoSendReactions(client: Client, message: Message):
reply = message.reply_to_message

Expand All @@ -53,24 +55,21 @@ async def AutoSendReactions(client: Client, message: Message):
# return

if not sqlite.get("AutoSendReactions.Enable"):
sqlite["AutoSendReactions.Enable"] = 'yes'
sqlite["AutoSendReactions.Enable"] = "yes"

# 返回消息
await edit_delete(message, "✅ **已启用自动回复表情插件**")

elif message.parameter[0] == "disable":

if sqlite.get("AutoSendReactions.Enable"):
del sqlite["AutoSendReactions.Enable"]

# 返回消息
await edit_delete(message, "❌ **已停用自动回复表情插件**")

elif message.parameter[0] in ["set", "unset"]:

## 设置插件
if (message.parameter[0] == "set"):

if message.parameter[0] == "set":
if not reply and (len(message.parameter) == 3):
target = message.parameter[1]
content = message.parameter[2]
Expand All @@ -83,7 +82,7 @@ async def AutoSendReactions(client: Client, message: Message):
if not content or not get_emoji(content):
return await message.edit("❌ **Emoji参数不能为空或不合法**")
user_name = (
f'{user_info.first_name} {user_info.last_name}'
f"{user_info.first_name} {user_info.last_name}"
if user_info.last_name
else user_info.first_name
)
Expand All @@ -92,7 +91,7 @@ async def AutoSendReactions(client: Client, message: Message):
sqlite[f"AutoSendReactions.{target}"] = content
await edit_delete(
message,
f"✅ 已{'更新' if hasSetted else '添加'}对 __{user_name}__ 的自动回复Emoji设置**"
f"✅ 已{'更新' if hasSetted else '添加'}对 __{user_name}__ 的自动回复Emoji设置**",
)
except Exception as e:
await message.edit(message, f"❌ **在设置中遇到了一些错误** > {e}")
Expand All @@ -107,7 +106,7 @@ async def AutoSendReactions(client: Client, message: Message):
if not content or not get_emoji(content):
return await message.edit("❌ **Emoji参数不能为空或不合法**")
user_name = (
f'{from_user.first_name} {from_user.last_name}'
f"{from_user.first_name} {from_user.last_name}"
if from_user.last_name
else from_user.first_name
)
Expand All @@ -116,17 +115,15 @@ async def AutoSendReactions(client: Client, message: Message):
sqlite[f"AutoSendReactions.{target}"] = content
await edit_delete(
message,
f"✅ 已{'更新' if hasSetted else '添加'}对 __{user_name}__ 的自动回复Emoji设置"
f"✅ 已{'更新' if hasSetted else '添加'}对 __{user_name}__ 的自动回复Emoji设置",
)
except Exception as e:
await message.edit(message, f"❌ **在设置中遇到了一些错误** > {e}")
await log(e) # 打印错误日志
else:
return await message.edit(
f"{lang('error_prefix')}{lang('arg_error')}")

elif (message.parameter[0] == "unset"):
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")

elif message.parameter[0] == "unset":
if not reply and (len(message.parameter) == 2):
target = message.parameter[1]
try:
Expand All @@ -137,17 +134,19 @@ async def AutoSendReactions(client: Client, message: Message):
return await message.edit("❌ **目标用户不存在或参数有误**")
user_id = user_info.id
user_name = (
f'{user_info.first_name} {user_info.last_name}'
f"{user_info.first_name} {user_info.last_name}"
if user_info.last_name
else user_info.first_name
)
if hasSetted := sqlite.get(f"AutoSendReactions.{user_id}"):
del sqlite[f"AutoSendReactions.{user_id}"]
await edit_delete(
message, f"✅ 对 __{user_name}__ 的自动回复Emoji设置已删除")
message, f"✅ 对 __{user_name}__ 的自动回复Emoji设置已删除"
)
else:
await edit_delete(
message, f"❌ 还没有对 __{user_name}__ 设置自动回复Emoji哦~")
message, f"❌ 还没有对 __{user_name}__ 设置自动回复Emoji哦~"
)
except Exception as e:
await message.edit(message, f"❌ **在设置中遇到了一些错误** > {e}")
await log(e) # 打印错误日志
Expand All @@ -157,68 +156,69 @@ async def AutoSendReactions(client: Client, message: Message):
target = from_user.id
try:
user_name = (
f'{from_user.first_name} {from_user.last_name}'
f"{from_user.first_name} {from_user.last_name}"
if from_user.last_name
else from_user.first_name
)
if hasSetted := sqlite.get(f"AutoSendReactions.{target}"):
del sqlite[f"AutoSendReactions.{target}"]
await edit_delete(
message, f"✅ 已删除对 __{user_name}__ 的自动回复Emoji设置")
message, f"✅ 已删除对 __{user_name}__ 的自动回复Emoji设置"
)
else:
await edit_delete(
message, f"❌ 还没有对 __{user_name}__ 设置自动回复Emoji哦~")
message, f"❌ 还没有对 __{user_name}__ 设置自动回复Emoji哦~"
)
except Exception as e:
await message.edit(message, f"❌ **在设置中遇到了一些错误** > {e}")
await log(e) # 打印错误日志
else:
return await message.edit(
f"{lang('error_prefix')}{lang('arg_error')}")
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")

else:
return await message.edit(
f"{lang('error_prefix')}{lang('arg_error')}")
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")

elif (message.parameter[0]
== "block") or (message.parameter[0] == "unblock") and (len(
message.parameter) == 2):
elif (
(message.parameter[0] == "block")
or (message.parameter[0] == "unblock")
and (len(message.parameter) == 2)
):
group = message.parameter[1]
group_info = await bot.get_chat(chat_id=group)
if not group_info:
return await message.edit("❌ **目标群组不存在或参数有误**")
group_id = group_info.id
group_name = group_info.title

if (message.parameter[0] == "block"):
if message.parameter[0] == "block":
if hasBlocked := sqlite.get(f"AutoSendReactionsBlock.{group_id}"):
await edit_delete(
message, f"❌ 已经将 __{group_name}__ 加入自动回复Emoji黑名单群组了哦~")
message, f"❌ 已经将 __{group_name}__ 加入自动回复Emoji黑名单群组了哦~"
)
else:
sqlite[f"AutoSendReactionsBlock.{group_id}"] = 'yes'
await edit_delete(message,
f"✅ 已将 __{group_name}__ 加入至自动回复Emoji黑名单群组")
elif (message.parameter[0] == "unblock"):
sqlite[f"AutoSendReactionsBlock.{group_id}"] = "yes"
await edit_delete(message, f"✅ 已将 __{group_name}__ 加入至自动回复Emoji黑名单群组")
elif message.parameter[0] == "unblock":
if hasBlocked := sqlite.get(f"AutoSendReactionsBlock.{group_id}"):
del sqlite[f"AutoSendReactionsBlock.{group_id}"]
await edit_delete(message,
f"✅ 已将 __{group_name}__ 从自动回复Emoji黑名单群组中移除")
await edit_delete(message, f"✅ 已将 __{group_name}__ 从自动回复Emoji黑名单群组中移除")
else:
await edit_delete(
message, f"❌ 还没有将 __{group_name}__ 加入进自动回复Emoji群组黑名单哦~")
message, f"❌ 还没有将 __{group_name}__ 加入进自动回复Emoji群组黑名单哦~"
)

else:
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}"
)
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")


@listener(is_plugin=False, incoming=True, ignore_edited=True)
async def AutoSendReactions(message: Message):
from_user = ''
from_user = ""
try:
# 判断是否启用了本插件
if not sqlite.get("AutoSendReactions.Enable"):
return
if 'GROUP' not in str(message.chat.type):
if "GROUP" not in str(message.chat.type):
return
# 判断是否在黑名单中
if sqlite.get(f"AutoSendReactionsBlock.{message.chat.id}"):
Expand All @@ -236,9 +236,9 @@ async def AutoSendReactions(message: Message):
return

# 发送表情
emoji = sqlite.get(f"AutoSendReactions.{from_user.id}").split('|')[0]
emoji = sqlite.get(f"AutoSendReactions.{from_user.id}").split("|")[0]
user_name = (
f'{from_user.first_name} {from_user.last_name}'
f"{from_user.first_name} {from_user.last_name}"
if from_user.last_name
else from_user.first_name
)
Expand Down
Loading

0 comments on commit a7a3420

Please sign in to comment.