mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 19:24:23 +00:00
Adapt mod_jsonrpc to the new asyncio approach.
This commit is contained in:
@@ -4,16 +4,23 @@ from typing import TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from mods.jsonrpc.mod_jsonrpc import Jsonrpc
|
||||
|
||||
def thread_subscribe(uplink: 'Jsonrpc') -> None:
|
||||
async def thread_subscribe(uplink: 'Jsonrpc') -> None:
|
||||
|
||||
snickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
schannel = uplink.ctx.Config.SERVICE_CHANLOG
|
||||
if uplink.is_streaming:
|
||||
await uplink.ctx.Irc.Protocol.send_priv_msg(nick_from=snickname,
|
||||
msg=f"[{uplink.ctx.Config.COLORS.green}JSONRPC INFO{uplink.ctx.Config.COLORS.nogc}] IRCd Json-rpc already connected!",
|
||||
channel=schannel
|
||||
)
|
||||
return None
|
||||
|
||||
snickname = uplink.Config.SERVICE_NICKNAME
|
||||
schannel = uplink.Config.SERVICE_CHANLOG
|
||||
uplink.is_streaming = True
|
||||
response = asyncio.run(uplink.LiveRpc.subscribe(["all"]))
|
||||
response = await uplink.LiveRpc.subscribe(["all"])
|
||||
|
||||
if response.error.code != 0:
|
||||
uplink.Protocol.send_priv_msg(nick_from=snickname,
|
||||
msg=f"[{uplink.Config.COLORS.red}JSONRPC ERROR{uplink.Config.COLORS.nogc}] {response.error.message}",
|
||||
await uplink.ctx.Irc.Protocol.send_priv_msg(nick_from=snickname,
|
||||
msg=f"[{uplink.ctx.Config.COLORS.red}JSONRPC ERROR{uplink.ctx.Config.COLORS.nogc}] {response.error.message}",
|
||||
channel=schannel
|
||||
)
|
||||
|
||||
@@ -21,33 +28,41 @@ def thread_subscribe(uplink: 'Jsonrpc') -> None:
|
||||
message = response.error.message
|
||||
|
||||
if code == 0:
|
||||
uplink.Protocol.send_priv_msg(
|
||||
await uplink.ctx.Irc.Protocol.send_priv_msg(
|
||||
nick_from=snickname,
|
||||
msg=f"[{uplink.Config.COLORS.green}JSONRPC{uplink.Config.COLORS.nogc}] Stream is OFF",
|
||||
msg=f"[{uplink.ctx.Config.COLORS.green}JSONRPC{uplink.ctx.Config.COLORS.nogc}] Stream is OFF",
|
||||
channel=schannel
|
||||
)
|
||||
uplink.is_streaming = False
|
||||
else:
|
||||
uplink.Protocol.send_priv_msg(
|
||||
await uplink.ctx.Irc.Protocol.send_priv_msg(
|
||||
nick_from=snickname,
|
||||
msg=f"[{uplink.Config.COLORS.red}JSONRPC{uplink.Config.COLORS.nogc}] Stream has crashed! {code} - {message}",
|
||||
msg=f"[{uplink.ctx.Config.COLORS.red}JSONRPC{uplink.ctx.Config.COLORS.nogc}] Stream has crashed! {code} - {message}",
|
||||
channel=schannel
|
||||
)
|
||||
uplink.is_streaming = False
|
||||
|
||||
def thread_unsubscribe(uplink: 'Jsonrpc') -> None:
|
||||
async def thread_unsubscribe(uplink: 'Jsonrpc') -> None:
|
||||
|
||||
response = asyncio.run(uplink.LiveRpc.unsubscribe())
|
||||
uplink.Logs.debug("[JSONRPC UNLOAD] Unsubscribe from the stream!")
|
||||
snickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
schannel = uplink.ctx.Config.SERVICE_CHANLOG
|
||||
|
||||
if not uplink.is_streaming:
|
||||
await uplink.ctx.Irc.Protocol.send_priv_msg(nick_from=snickname,
|
||||
msg=f"[{uplink.ctx.Config.COLORS.green}JSONRPC INFO{uplink.ctx.Config.COLORS.nogc}] IRCd Json-rpc is already off!",
|
||||
channel=schannel
|
||||
)
|
||||
return None
|
||||
|
||||
response = await uplink.LiveRpc.unsubscribe()
|
||||
uplink.ctx.Logs.debug("[JSONRPC UNLOAD] Unsubscribe from the stream!")
|
||||
uplink.is_streaming = False
|
||||
uplink.update_configuration('jsonrpc', 0)
|
||||
snickname = uplink.Config.SERVICE_NICKNAME
|
||||
schannel = uplink.Config.SERVICE_CHANLOG
|
||||
|
||||
code = response.error.code
|
||||
message = response.error.message
|
||||
|
||||
if code != 0:
|
||||
uplink.Protocol.send_priv_msg(
|
||||
await uplink.ctx.Irc.Protocol.send_priv_msg(
|
||||
nick_from=snickname,
|
||||
msg=f"[{uplink.Config.COLORS.red}JSONRPC ERROR{uplink.Config.COLORS.nogc}] {message} ({code})",
|
||||
msg=f"[{uplink.ctx.Config.COLORS.red}JSONRPC ERROR{uplink.ctx.Config.COLORS.nogc}] {message} ({code})",
|
||||
channel=schannel
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user