diff --git a/core/lib/context.py b/core/lib/context.py index 6ece721..9693969 100644 --- a/core/lib/context.py +++ b/core/lib/context.py @@ -1,12 +1,18 @@ -def construct_query(index, net, channel, src, num, size): +def construct_query(index, net, channel, src, num, size, nicks=None): # Get the initial query extra_must = [] + extra_should = [] + extra_should2 = [] if num: extra_must.append({"match": {"num": num}}) if net: extra_must.append({"match": {"net": net}}) if channel: extra_must.append({"match": {"channel": channel}}) + if nicks: + print("NICKS", nicks) + for nick in nicks: + extra_should2.append({"match": {"nick": nick}}) types = ["msg", "notice", "action", "kick", "topic", "mode"] fields = [ "nick", @@ -19,11 +25,13 @@ def construct_query(index, net, channel, src, num, size): "net", "src", ] - if index == "int": - fields.append("mtype") - query_should = [{"match": {"mtype": x}} for x in types] - else: - query_should = [{"match": {"type": x}} for x in types] + # if index == "int": + # fields.append("mtype") + # for ctype in types: + # extra_should.append({"match": {"mtype": ctype}}) + # else: + # for ctype in types: + # extra_should.append({"match": {"type": ctype}}) query = { "size": size, "query": { @@ -32,7 +40,12 @@ def construct_query(index, net, channel, src, num, size): {"match": {"src": src}}, { "bool": { - "should": query_should, + "should": [*extra_should], + } + }, + { + "bool": { + "should": [*extra_should2], } }, *extra_must, @@ -42,5 +55,5 @@ def construct_query(index, net, channel, src, num, size): "fields": fields, "_source": False, } - print("QUERY", query) + return query diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 4a98b5c..c9256f1 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -203,3 +203,9 @@ def send_irc_message(net, num, channel, msg, nick=None): payload["nick"] = nick messaged = threshold_request(url, payload, method="PUT") return messaged + +def get_irc_nick(net, num): + url = f"irc/nick/{net}/{num}" + payload = {} + nick = threshold_request(url, payload, method="GET") + return nick \ No newline at end of file diff --git a/core/views/ui/drilldown.py b/core/views/ui/drilldown.py index 923ba21..3228e72 100644 --- a/core/views/ui/drilldown.py +++ b/core/views/ui/drilldown.py @@ -19,7 +19,7 @@ from core.lib.threshold import ( get_users, ) from core.views.ui.tables import DrilldownTable - +from core.lib import threshold def parse_dates(dates): spl = dates.split(" - ") @@ -244,6 +244,7 @@ class DrilldownContextModal(APIView): self.template_name = "modals/context_table.html" size = 20 + nicks = None # Create the query params from the POST arguments mandatory = ["net", "channel", "num", "src", "index", "nick"] invalid = [None, False, "—", "None"] @@ -257,6 +258,12 @@ class DrilldownContextModal(APIView): if query_params["index"] == "int": if "mtype" not in query_params: query_params["mtype"] = None + if request.user.is_superuser: + if query_params["type"] == "query": + #bot_nick = threshold.irc_get_nick(query_params["net"], query_params["num"]) + print("BOT NICK", query_params["channel"]) + print("QUERY NICK", query_params["nick"]) + nicks = [query_params["channel"], query_params["nick"]] query_params["sorting"] = "desc" if ( query_params["index"] == "int" @@ -272,6 +279,7 @@ class DrilldownContextModal(APIView): query_params["src"], query_params["num"], size, + nicks=nicks, ) results = query_results( request, query_params, annotate=True, custom_query=search_query