forked from nyaoouo/FFxivPythonTrigger2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
56 lines (44 loc) · 1.73 KB
/
Copy path__init__.py
File metadata and controls
56 lines (44 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from FFxivPythonTrigger import PluginBase, api
from aiohttp import web
from . import DoTextCommand, DoAction, AddressManager
class Magics(object):
@staticmethod
def macro_command(macro):
DoTextCommand.do_text_command(macro)
do_action = DoAction
@staticmethod
def echo_msg(msg):
DoTextCommand.do_text_command("/e %s" % msg)
class XivMagic(PluginBase):
name = "XivMagic"
git_repo = 'nyaoouo/FFxivPythonTrigger2'
repo_path = 'plugins/XivMagic'
hash_path = os.path.dirname(__file__)
async def text_command_handler(self, request: web.Request):
cmd=await request.text()
DoTextCommand.do_text_command(cmd)
self.logger.debug("text_command_handler",cmd)
return web.json_response({'msg': 'success'})
async def use_item_handler(self, request: web.Request):
try:
item_id = int(await request.text())
except ValueError:
return web.json_response({'msg': 'Value Error'})
paths = request.path.strip('/').split('/')
if len(paths) > 1 and paths[1] == 'hq':
item_id += 1000000
self.logger.debug("use_item_handler",item_id)
DoAction.use_item(item_id)
return web.json_response({'msg': 'success'})
def __init__(self):
super().__init__()
self.api_class = Magics()
self.register_api("Magic", self.api_class)
api.HttpApi.register_post_route('command', self.text_command_handler)
api.HttpApi.register_post_route('useitem', self.use_item_handler)
def _start(self):
self.api_class.echo_msg("magic started")
def _onunload(self):
api.HttpApi.unregister_post_route('command')
api.HttpApi.unregister_post_route('useitem')