Fire a fake event when we send a message
This commit is contained in:
parent
719f014265
commit
220ce976f2
24
api/views.py
24
api/views.py
|
@ -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}"})
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue