1010from . import tools
1111from .commands import ChatType , MessageType , register_commands
1212from .command_builder import CommandBuilder
13- from .config import *
13+ from .config import ConfigManager
1414from .const import VERSION , VERSION_STR
1515from .telegram_manager import TelegramBot
1616
@@ -33,22 +33,21 @@ async def on_load(server: PluginServerInterface, old):
3333 """
3434 插件加载操作
3535 """
36- global bindings , ban_list , bot , logger
3736
3837 ConfigManager .load_data (server )
3938
40- online_player_api = server .get_plugin_instance ("online_player_api" )
41- if online_player_api is None : raise Exception ("Unable to load dependency \" online_player_api\" " )
39+ ConfigManager . online_player_api = server .get_plugin_instance ("online_player_api" )
40+ if ConfigManager . online_player_api is None : raise Exception ("Unable to load dependency \" online_player_api\" " )
4241
4342 async def action (event : Update , context : ContextTypes .DEFAULT_TYPE ):
4443 await on_message (server , event , context )
4544
46- bot = TelegramBot (server .logger , ConfigManager .config .telegram ["token" ]) if ConfigManager .config .telegram ["api" ] is None else TelegramBot (server .logger , ConfigManager .config .telegram ["token" ], ConfigManager .config .telegram ["api" ])
47- bot .action = action
48- bot .register ()
49- bot .start (True )
45+ ConfigManager . bot = TelegramBot (server .logger , ConfigManager .config .telegram ["token" ]) if ConfigManager .config .telegram ["api" ] is None else TelegramBot (server .logger , ConfigManager .config .telegram ["token" ], ConfigManager .config .telegram ["api" ])
46+ ConfigManager . bot .action = action
47+ ConfigManager . bot .register ()
48+ ConfigManager . bot .start (True )
5049
51- logger = server .logger
50+ ConfigManager . logger = server .logger
5251 register_commands ()
5352
5453 server .register_help_message ("!!tg" , "向 Telegram 群聊发送聊天信息" )
@@ -62,7 +61,7 @@ async def action(event: Update, context: ContextTypes.DEFAULT_TYPE):
6261 # await tools.send_to_group(tip)
6362 server .say (f"§7{ tip } " )
6463
65- def on_unload (server : PluginServerInterface ): bot .stop () if bot is not None else None
64+ def on_unload (server : PluginServerInterface ): ConfigManager . bot .stop () if ConfigManager . bot is not None else None
6665
6766async def on_user_info (server : PluginServerInterface , info : Info ):
6867 if ConfigManager .config .forwardings ["mc_to_tg" ] is True and info .player :
@@ -81,7 +80,7 @@ async def on_message(server: PluginServerInterface, event: Update, context: Cont
8180 content = event .message .text
8281 if content is None : return
8382 event_type = tools .parse_event_type (event )
84- logger .debug (f"Update 数据:\n { event } " )
83+ ConfigManager . logger .debug (f"Update 数据:\n { event } " )
8584
8685 typ = tools .get_type (event )
8786 # 防止自己的机器人被别人拉去用还越权
@@ -96,11 +95,11 @@ async def on_message(server: PluginServerInterface, event: Update, context: Cont
9695 # 普通信息
9796 if ConfigManager .config .forwardings ["tg_to_mc" ] is True and typ == ChatType .GROUP :
9897 id : str = str (tools .get_id (event ))
99- name : str = f"§a<{ bindings [id ]} >§7" if id in bindings else f"§4<{ event .message .chat .full_name } ({ id } )>§7"
98+ name : str = f"§a<{ ConfigManager . bindings [id ]} >§7" if id in ConfigManager . bindings else f"§4<{ event .message .chat .full_name } ({ id } )>§7"
10099 server .say (f"§7[TG] { name } : { content } " )
101100
102101 # 封禁列表,不作应答
103- if tools .get_id (event ) in ban_list :
102+ if tools .get_id (event ) in ConfigManager . ban_list :
104103 server .logger .debug (f"用户 { tools .get_id (event )} 已被封禁,拒绝处理其请求" )
105104 return
106105
@@ -113,13 +112,11 @@ async def mc_command_tg(src: CommandSource, ctx: CommandContext):
113112 player = "Console"
114113 if src .is_player :
115114 player = src .player # type: ignore
116- if player not in bindings .values ():
115+ if player not in ConfigManager . bindings .values ():
117116 src .reply ("请先在群内绑定你的账号!" )
118117 return
119- elif (not str (next ((key for key , value in bindings .items () if value == player ), 0 )) in ConfigManager .config .admins and not src .has_permission (2 )) and (player != "Console" ):
118+ elif (not str (next ((key for key , value in ConfigManager . bindings .items () if value == player ), 0 )) in ConfigManager .config .admins and not src .has_permission (2 )) and (player != "Console" ):
120119 src .reply ("你没有足够的权限!" )
121120 return
122121 msg = f"{ player } :\n { ctx ['message' ]} "
123- await tools .send_to_group (msg , entities = [MessageEntity ("bold" , 0 , len (player ) + 1 )])
124-
125- __all__ = ["bot" , "command_tree" , "logger" ]
122+ await tools .send_to_group (msg , entities = [MessageEntity ("bold" , 0 , len (player ) + 1 )])
0 commit comments