Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
feat(farmer): add share_to
Browse files Browse the repository at this point in the history
Signed-off-by: hldh214 <[email protected]>
  • Loading branch information
hldh214 committed Aug 20, 2023
1 parent 5cf726b commit c2c89dc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
8 changes: 7 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@
"level": []
}
],
"radius": 8
"radius": 8,
"share_to": {
"chat_channels": [
1,
2
]
}
},
"interval": {
"start": 1,
Expand Down
12 changes: 12 additions & 0 deletions lokbot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lokbot/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions lokbot/farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit c2c89dc

Please sign in to comment.