Skip to content

Commit

Permalink
feat(bot): ✨ always parse name in command handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Dec 21, 2023
1 parent e517c16 commit cfdf9ba
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions bot/bot/command_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def __command_spawn(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.botOnline', e.name))

def __command_kill(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
try:
self.__plugin.bot_manager.kill(name)
src.reply(RTextMCDRTranslation('bot.command.killed', name))
Expand All @@ -466,7 +466,7 @@ def __command_kill(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.botOffline', e.name))

def __command_action(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
try:
self.__plugin.bot_manager.action(
name, ctx.get('index')
Expand Down Expand Up @@ -530,14 +530,16 @@ def __command_tag_kill(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.tagNotExists', tag))

def __command_info(self, src: Source, ctx: Dict[str, Any]):
name = self.parse_name(ctx['name'])

def get_config_button(
name: str,
bot_name: str,
config: str,
default_value: str
) -> RText:
"""
Get a RText config button.
:param name: Name of the bot.
:param bot_name: Name of the bot.
:param config: Config name.
:param default_value: Default value of the config.
:return: RText.
Expand All @@ -549,12 +551,12 @@ def get_config_button(
)
.c(
RAction.suggest_command,
f'!!bot config {name} {config} {default_value}'
f'!!bot config {bot_name} {config} {default_value}'
)
)

try:
bot = self.__plugin.bot_manager.get_bot(ctx['name'])
bot = self.__plugin.bot_manager.get_bot(name)
minimap_button = RTextList(
RText('[+V]', color=RColor.aqua)
.h(
Expand Down Expand Up @@ -799,7 +801,7 @@ def __command_save(self, src: Source, ctx: Dict[str, Any]):
)

def __command_del(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
try:
self.__plugin.bot_manager.delete(name)
src.reply(RTextMCDRTranslation('bot.command.deleted', name))
Expand All @@ -809,7 +811,7 @@ def __command_del(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.botNotSaved', e.name))

def __command_config_name(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
new_name = self.parse_name(ctx['new_name'])
try:
self.__plugin.bot_manager.get_bot(name).set_name(new_name)
Expand All @@ -824,7 +826,7 @@ def __command_config_name(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.botNotExists', e.name))

def __command_config_position(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
position = ctx['position']
try:
bot = self.__plugin.bot_manager.get_bot(name)
Expand All @@ -842,7 +844,7 @@ def __command_config_position(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.botNotExists', e.name))

def __command_config_facing(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
facing = ctx['facing']
try:
bot = self.__plugin.bot_manager.get_bot(name)
Expand All @@ -860,7 +862,7 @@ def __command_config_facing(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.botNotExists', e.name))

def __command_config_dimension(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
dimension = ctx['dimension']
try:
bot = self.__plugin.bot_manager.get_bot(name)
Expand All @@ -887,7 +889,7 @@ def __command_config_dimension(self, src: Source, ctx: Dict[str, Any]):
)

def __command_config_comment(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
comment = ctx['comment']
try:
if comment.startswith('"') and comment.endswith('"'):
Expand All @@ -905,7 +907,7 @@ def __command_config_comment(self, src: Source, ctx: Dict[str, Any]):
def __command_config_actions_append(
self, src: Source, ctx: Dict[str, Any]
):
name = ctx['name']
name = self.parse_name(ctx['name'])
action = ctx['action']
try:
bot = self.__plugin.bot_manager.get_bot(name)
Expand All @@ -924,7 +926,7 @@ def __command_config_actions_append(
def __command_config_actions_insert(
self, src: Source, ctx: Dict[str, Any]
):
name = ctx['name']
name = self.parse_name(ctx['name'])
index = ctx['index']
action = ctx['action']
try:
Expand Down Expand Up @@ -952,7 +954,7 @@ def __command_config_actions_insert(
def __command_config_actions_delete(
self, src: Source, ctx: Dict[str, Any]
):
name = ctx['name']
name = self.parse_name(ctx['name'])
index = ctx['index']
try:
bot = self.__plugin.bot_manager.get_bot(name)
Expand All @@ -977,7 +979,7 @@ def __command_config_actions_delete(
))

def __command_config_actions_edit(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
index = ctx['index']
action = ctx['action']
try:
Expand All @@ -1003,7 +1005,7 @@ def __command_config_actions_edit(self, src: Source, ctx: Dict[str, Any]):
))

def __command_config_actions_clear(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
try:
self.__plugin.bot_manager.get_bot(name).set_actions([])
self.__plugin.bot_manager.save_data()
Expand All @@ -1016,7 +1018,7 @@ def __command_config_actions_clear(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.botNotExists', e.name))

def __command_config_tags_append(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
tag = ctx['tag']
try:
bot = self.__plugin.bot_manager.get_bot(name)
Expand All @@ -1033,7 +1035,7 @@ def __command_config_tags_append(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.botNotExists', e.name))

def __command_config_tags_insert(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
index = ctx['index']
tag = ctx['tag']
try:
Expand All @@ -1059,7 +1061,7 @@ def __command_config_tags_insert(self, src: Source, ctx: Dict[str, Any]):
))

def __command_config_tags_delete(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
index = ctx['index']
try:
bot = self.__plugin.bot_manager.get_bot(name)
Expand All @@ -1084,7 +1086,7 @@ def __command_config_tags_delete(self, src: Source, ctx: Dict[str, Any]):
))

def __command_config_tags_edit(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
index = ctx['index']
tag = ctx['tag']
try:
Expand All @@ -1110,7 +1112,7 @@ def __command_config_tags_edit(self, src: Source, ctx: Dict[str, Any]):
))

def __command_config_tags_clear(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
try:
self.__plugin.bot_manager.get_bot(name).set_tags([])
self.__plugin.bot_manager.save_data()
Expand All @@ -1123,7 +1125,7 @@ def __command_config_tags_clear(self, src: Source, ctx: Dict[str, Any]):
src.reply(RTextMCDRTranslation('bot.error.botNotExists', e.name))

def __command_config_auto_login(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
auto_login = ctx['autoLogin']
try:
self.__plugin.bot_manager.get_bot(name).set_auto_login(auto_login)
Expand All @@ -1139,7 +1141,7 @@ def __command_config_auto_login(self, src: Source, ctx: Dict[str, Any]):
def __command_config_auto_run_actions(
self, src: Source, ctx: Dict[str, Any]
):
name = ctx['name']
name = self.parse_name(ctx['name'])
auto_run_actions = ctx['autoRunActions']
try:
self.__plugin.bot_manager.get_bot(name).set_auto_run_actions(
Expand All @@ -1156,7 +1158,7 @@ def __command_config_auto_run_actions(
src.reply(RTextMCDRTranslation('bot.error.botNotExists', e.name))

def __command_config_auto_update(self, src: Source, ctx: Dict[str, Any]):
name = ctx['name']
name = self.parse_name(ctx['name'])
auto_update = ctx['autoUpdate']
try:
self.__plugin.bot_manager.get_bot(name).set_auto_update(
Expand Down

0 comments on commit cfdf9ba

Please sign in to comment.