Fire a fake event when we send a message

This commit is contained in:
Mark Veidemanis 2022-08-09 07:20:30 +01:00
parent 719f014265
commit 220ce976f2
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 28 additions and 0 deletions

View File

@ -478,3 +478,27 @@ class API(object):
return dumps({"success": False, "reason": f"could not get first relay for {net}"}) return dumps({"success": False, "reason": f"could not get first relay for {net}"})
first_relay.list() first_relay.list()
return dumps({"success": True, "message": f"requested list with instance {first_relay.num} of {net}"}) return dumps({"success": True, "message": f"requested list with instance {first_relay.num} of {net}"})
@app.route("/irc/msg/<net>/<num>/<channel>/", methods=["PUT"])
@login_required
def irc_send_message(self, request, net, num, channel):
print("IRC SEND", net, num, channel)
try:
data = loads(request.content.read())
except JSONDecodeError:
return "Invalid JSON"
if "msg" not in data:
return dumps({"success": False, "reason": "no msg."})
msg = data["msg"]
if net not in main.network.keys():
return dumps({"success": False, "reason": "no such net."})
if not num.isdigit():
return dumps({"success": False, "reason": "invalid num: not a number."})
num = int(num)
if num not in main.network[net].relays.keys():
return dumps({"success": False, "reason": f"no relay {num} on {net}"})
name = f"{net}{num}"
if name not in main.IRCPool.keys():
return dumps({"success": False, "reason": f"relay {num} not on {net}"})
main.IRCPool[name].sendmsg(channel, msg)
return dumps({"success": True, "message": f"sent message to {channel} on {name}"})

View File

@ -252,6 +252,10 @@ class IRCBot(IRCClient):
def action(self, user, channel, msg): def action(self, user, channel, msg):
self.event(type="action", muser=user, channel=channel, msg=msg) self.event(type="action", muser=user, channel=channel, msg=msg)
def sendmsg(self, channel, msg):
self.event(type="self", mtype="msg", channel=channel, nick=self.nickname, msg=msg)
self.msg(channel, msg)
def get(self, var): def get(self, var):
try: try:
result = getattr(self, var) result = getattr(self, var)