Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Nov 21, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

Comment on lines -375 to +384
if args[0] == "on":
debugon()
logging.getLogger().setLevel(logging.DEBUG)
logger.remove()
logger.add(sys.stdout, level="INFO")
logger.info("输出等级设置为 DEBUG.")
return await matcher.send(
manager.process_generic_event("DebugOn", event=event)
)
else:
if args[0] != "on":
return await matcher.send("错误, 我无法解析你的指令.")
debugon()
logging.getLogger().setLevel(logging.DEBUG)
logger.remove()
logger.add(sys.stdout, level="INFO")
logger.info("输出等级设置为 DEBUG.")
return await matcher.send(
manager.process_generic_event("DebugOn", event=event)
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function debughandler refactored with the following changes:

Comment on lines -391 to +390
arg = list(filter(None, args.split(" ")))

if len(arg) >= 1:
if arg := list(filter(None, args.split(" "))):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function superuser_handler refactored with the following changes:

Comment on lines -578 to +575
reply = "从商店搜索到以下插件:\n"
reply += "Noctisynth 官方插件:\n"

reply = "从商店搜索到以下插件:\n" + "Noctisynth 官方插件:\n"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function bothandler refactored with the following changes:

Comment on lines -253 to +257
got = messages.get(args)
if got:
if got := messages.get(args):
return got

for key, alias in messages.keys.items():
relation = []
for alia in alias:
if alia:
relation.append(similar(alia, args))

relation = [similar(alia, args) for alia in alias if alia]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function help_message refactored with the following changes:

if len(args) == 0:
if not args:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DefaultRA.__call__ refactored with the following changes:

Comment on lines -51 to +35
if "official" in result.keys():
official = result["official"]
else:
official = {}

return official
return result["official"] if "official" in result.keys() else {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_official_plugins refactored with the following changes:

Comment on lines -64 to +43
if "community" in result.keys():
community = result["community"]
else:
community = {}

return community
return result["community"] if "community" in result.keys() else {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_community_plugins refactored with the following changes:

for name, method in vars(templates).items():
for method in vars(templates).values():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _load_template_methods refactored with the following changes:

logger.error(f"请确保您的回复配置文件包含了正确的键和相应的值。如果您不确定如何正确配置文件,请参考文档或向管理员寻求帮助。")
logger.error("请确保您的回复配置文件包含了正确的键和相应的值。如果您不确定如何正确配置文件,请参考文档或向管理员寻求帮助。")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _load_reply_file refactored with the following changes:

logger.error(f"初始化回复配置时出现异常。")
logger.error("初始化回复配置时出现异常。")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init_yaml_file refactored with the following changes:

Comment on lines -141 to +146
if response and is_enable:
result = self._handle_generic_event(response, **kwargs)
if result:
return result
else:
break
if response and is_enable:
result = self._handle_generic_event(response, **kwargs)
if result:
return result
else:
break
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ReplyRegistryManager.process_generic_event refactored with the following changes:

if len(result) == 0:
return None
return result
return None if len(result) == 0 else result
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ReplyRegistryManager.process_message_event refactored with the following changes:

logger.error(f"请确保您的回复配置文件包含了正确的键和相应的值。如果您不确定如何正确配置文件,请参考文档或向管理员寻求帮助。")
logger.error("请确保您的回复配置文件包含了正确的键和相应的值。如果您不确定如何正确配置文件,请参考文档或向管理员寻求帮助。")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ReplyRegistry.disable_event refactored with the following changes:

logger.error(f"请确保您的回复配置文件包含了正确的键和相应的值。如果您不确定如何正确配置文件,请参考文档或向管理员寻求帮助。")
logger.error("请确保您的回复配置文件包含了正确的键和相应的值。如果您不确定如何正确配置文件,请参考文档或向管理员寻求帮助。")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ReplyRegistry.enable_event refactored with the following changes:

logger.error(f"请确保您的回复配置文件包含了正确的键和相应的值。如果您不确定如何正确配置文件,请参考文档或向管理员寻求帮助。")
logger.error("请确保您的回复配置文件包含了正确的键和相应的值。如果您不确定如何正确配置文件,请参考文档或向管理员寻求帮助。")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ReplyRegistry.toggle refactored with the following changes:

Comment on lines -176 to +164
if split[0]:
self.a = int(split[0])
else:
self.a = 1

self.a = int(split[0]) if split[0] else 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PunishDice.parse refactored with the following changes:

Comment on lines -344 to +328
for roll_string in roll_strings.keys():
for roll_string in roll_strings:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 344-344 refactored with the following changes:

if judge:
self.judge = self.judge_dict[judge]
else:
self.judge = None
self.judge = self.judge_dict[judge] if judge else None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Docimasy.__init__ refactored with the following changes:

Comment on lines -38 to +35
if self.judge > 0:
return True
else:
return False
return self.judge > 0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Docimasy.__bool__ refactored with the following changes:

Comment on lines -45 to +40
toadd = toadd.lstrip("\n")
if toadd:
if self.detail:
self.detail = self.detail.strip("\n") + "\n" + toadd
else:
self.detail = toadd
if toadd := toadd.lstrip("\n"):
self.detail = self.detail.strip("\n") + "\n" + toadd if self.detail else toadd
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Docimasy.__add__ refactored with the following changes:

Comment on lines -39 to +44
message = str(message).lower() if lower else str(message)
message = message.lower() if lower else message
msg = translate_punctuation(
re.sub("\s+", " ", re.sub(regex, "", message)).strip(" ")
)
if msg.startswith("/"):
msg = "." + msg[1:]
msg = f".{msg[1:]}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function format_str refactored with the following changes:

Comment on lines -16 to +23
mentions = []
try:
message = json.loads(event.json())["message"]
except KeyError:
return []

for mention in message:
if mention["type"] == "at":
mentions.append(mention["data"]["qq"])

return mentions
return [
mention["data"]["qq"] for mention in message if mention["type"] == "at"
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_mentions refactored with the following changes:

Comment on lines -33 to +30
for _, obj in vars(main).items():
for obj in vars(main).values():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_handlers refactored with the following changes:

Comment on lines -85 to +87
if raw_json["card"]:
return raw_json["card"]
else:
return raw_json["nickname"]
return raw_json["card"] if raw_json["card"] else raw_json["nickname"]
except:
from .plugins import modes

cards = modes[get_mode(event)].__cards__
got = cards.get(event, qid=get_user_id(event))
if got:
if got := cards.get(event, qid=get_user_id(event)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_user_card refactored with the following changes:

Comment on lines -112 to +105
got = cards.get(event, qid=get_user_id(event))
if got:
if got := cards.get(event, qid=get_user_id(event)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_user_nickname refactored with the following changes:

if not path.exists():
return "欧若可"

return path.open(mode="r").read()
return "欧若可" if not path.exists() else path.open(mode="r").read()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_name refactored with the following changes:

Comment on lines -83 to +80
status_text = BOT_STATUS_FILE.read_text(encoding="utf-8")
if status_text:
if status_text := BOT_STATUS_FILE.read_text(encoding="utf-8"):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function load_status refactored with the following changes:

iter_args = [arg for arg in args]
iter_args = list(args)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CommandParser.shlex refactored with the following changes:

Comment on lines -37 to +47
else:
if module.__type__ == "plugin":
module_type = "插件"
elif module.__type__ == "library":
module_type = "库"

if hasattr(module, "__nbcommands__"):
commands: dict = module.__nbcommands__
else:
commands = {}
if module.__type__ == "library":
module_type = "库"

elif module.__type__ == "plugin":
module_type = "插件"
commands = module.__nbcommands__ if hasattr(module, "__nbcommands__") else {}
if commands and not hasattr(module, "__nbhandler__"):
logger.error(f"{module_type} {folder.name} 配置异常, 导入失败.")
continue

if hasattr(module, "__nbhandler__"):
handlers = module.__nbhandler__
else:
handlers = {}

handlers = module.__nbhandler__ if hasattr(module, "__nbhandler__") else {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function modules refactored with the following changes:

Comment on lines -16 to 30
if old_length == 5:
old_pre_release = old_tuple.group(4)[0]
old_pre_version = int(old_tuple.group(5))
elif old_length == 3:
if old_length == 3:
old_pre_release = "s"
old_pre_version = 1
elif old_length == 5:
old_pre_release = old_tuple.group(4)[0]
old_pre_version = int(old_tuple.group(5))
else:
return False

if new_length == 5:
new_pre_release = new_tuple.group(4)[0]
new_pre_version = int(new_tuple.group(5))
elif new_length == 3:
if new_length == 3:
new_pre_release = "s"
new_pre_version = 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function require_update refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants