diff --git a/config.example.json b/config.example.json index e22cd781..4601bc0a 100644 --- a/config.example.json +++ b/config.example.json @@ -89,7 +89,13 @@ "level": [] } ], - "radius": 8 + "radius": 8, + "share_to": { + "chat_channels": [ + 1, + 2 + ] + } }, "interval": { "start": 1, diff --git a/lokbot/client.py b/lokbot/client.py index 10a3e5e9..81308509 100644 --- a/lokbot/client.py +++ b/lokbot/client.py @@ -641,6 +641,18 @@ def field_march_info(self, data): def field_march_start(self, data): return self.post('field/march/start', data) + def chat_new(self, chat_channel, chat_type, text, param=None): + data = { + 'chatChannel': chat_channel, + 'chatType': chat_type, + 'text': text, + } + + if param: + data['param'] = param + + return self.post('chat/new', data) + def get_version(): first = 1 diff --git a/lokbot/enum.py b/lokbot/enum.py index 84a3aed8..0cca30ec 100644 --- a/lokbot/enum.py +++ b/lokbot/enum.py @@ -28,6 +28,15 @@ DRAGO_LAIR_STATUS_DEFENDING = 2 # 防守中 DRAGO_LAIR_STATUS_ATTACKING = 3 # 出击中 +# 聊天: 频道类型 +CHAT_CHANNEL_WORLD = 1 # 世界频道 +CHAT_CHANNEL_ALLIANCE = 2 # 联盟频道 + +# 聊天: 消息类型 +CHAT_TYPE_TEXT = 1 # 文字 +CHAT_TYPE_LOC = 2 # 位置 +CHAT_TYPE_STICKER = 7 # 贴纸 + BUILDING_POSITION_MAP = { 'academy': 5, 'castle': 1, diff --git a/lokbot/farmer.py b/lokbot/farmer.py index f044ee60..72865875 100644 --- a/lokbot/farmer.py +++ b/lokbot/farmer.py @@ -719,7 +719,7 @@ def on_task_update(data): retry=tenacity.retry_if_not_exception_type(FatalApiException), reraise=True ) - def socf_thread(self, radius, targets): + def socf_thread(self, radius, targets, share_to=None): """ websocket connection of the field :return: @@ -767,14 +767,20 @@ def on_field_objects(data): continue code = each_obj.get('code') + level = each_obj.get('level') + loc = each_obj.get('loc') level_whitelist = [target['level'] for target in targets if target['code'] == code] if not level_whitelist: # not the one we are looking for continue + if share_to and share_to.get('chat_channels'): + for chat_channel in share_to.get('chat_channels'): + self.api.chat_new(chat_channel, CHAT_TYPE_LOC, f'Lv.{level}?fo_{code}', {'loc': loc}) + level_whitelist = level_whitelist[0] - if level_whitelist and each_obj.get('level') not in level_whitelist: + if level_whitelist and level not in level_whitelist: logger.info(f'ignore: {each_obj}, level not in whitelist: {level_whitelist}') continue @@ -786,7 +792,8 @@ def on_field_objects(data): self._on_field_objects_monster(each_obj) except OtherException as error_code: if str(error_code) in ( - 'full_task', 'not_enough_troop', 'insufficient_actionpoint', 'not_open_gate' + 'full_task', 'not_enough_troop', 'insufficient_actionpoint', 'not_open_gate', + 'no_drago_action_point' ): logger.warning(f'on_field_objects: {error_code}, skip') self.field_object_processed = True