From 8dc9755c46394be0fb4032e499cab0e15c168f0d Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Wed, 22 May 2024 21:07:48 -0500 Subject: [PATCH] Status support, fix minor bug in data logic --- bot.py | 3 +++ commands.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/bot.py b/bot.py index 6ed5c0d..2fde3cb 100644 --- a/bot.py +++ b/bot.py @@ -52,6 +52,7 @@ class bot(bare.bot): else "FireBot" ) self.queue: list[bbytes] = [] # pyright: ignore [reportInvalidTypeForm] + self.statuses = {'firepup': {}} self.sock = socket(AF_INET, SOCK_STREAM) self.current = "user" self.threads = ( @@ -233,6 +234,8 @@ class bot(bare.bot): if self.queue: return bytes(self.queue.pop(0)) data = bytes(self.sock.recv(2048)) + if data.lazy_decode() == "": + return data while not data.endswith(b"\r\n"): data += bytes(self.sock.recv(2048)) data = bytes(data.strip(b"\r\n")) diff --git a/commands.py b/commands.py index f8a3151..9154ad7 100644 --- a/commands.py +++ b/commands.py @@ -213,6 +213,50 @@ def markov(bot: bare.bot, chan: str, name: str, message: str) -> None: bot.msg(proposed, chan) +def setStatus(bot: bare.bot, chan: str, name: str, message: str) -> None: + user, stat, reas = ('', 0, '') + try: + if message.split(' ')[1] == "help": + bot.msg("Assuming you want help with status codes. 1 is Availiable, 2 is Busy, 3 is Unavailiable, anything else is Unknown.", chan) + return + message = message.split(' ', 1)[1] + user = message.split(' ')[0].lower() + stat = int(message.split(' ')[1]) + reas = message.split(' ', 2)[2] + except IndexError: + bot.msg(f"Insufficent information to set a status. Expected 3 args. Only got {len(message.split(' ', 1)) - 1} args.", chan) + return + except ValueError: + bot.msg("Status parameter must be an int.", chan) + return + match stat: + case 1: + stat = "Availiable" + case 2: + stat = "Busy" + case 3: + stat = "Unavailiable" + case _: + stat = "Unknown" + if user in ["me", "my", "I"]: + user = 'firepup' + bot.statuses[user] = {'status': stat, 'reason': reas} + bot.msg(f"Status set for '{user}'. Raw data: {bot.statuses[user]}", chan) + + +def getStatus(bot: bare.bot, chan: str, name: str, message: str) -> None: + user = '' + try: + user = message.split(' ')[1] + except IndexError: + user = 'firepup' + bot.msg(f"[DEBUG] {user} - {bot.statuses.get(user)} (msg in was {message.split(' ')})", chan) + if bot.statuses.get(user) is None: + bot.msg("You've gotta provide a nick I actually recognize.", chan) + return + bot.msg(f"{user}'s status: {'Unknown' if not bot.statuses[user].get('status') else bot.statuses[user]['status']} - {'Reason unset' if not bot.statuses[user].get('reason') else bot.statuses[user]['reason']}", chan) + + data: dict[str, dict[str, Any]] = { "!botlist": {"prefix": False, "aliases": []}, "bugs bugs bugs": {"prefix": False, "aliases": []}, @@ -244,6 +288,8 @@ data: dict[str, dict[str, Any]] = { "version": {"prefix": True, "aliases": ["ver", "v"]}, "np": {"prefix": True, "aliases": []}, "markov": {"prefix": True, "aliases": ["m"]}, + "setStatus": {"prefix": True, "aliases": ["sS"], "check": checks.admin}, + "getStatus": {"prefix": True, "aliases": ["gS"]}, } regexes: list[str] = [conf.npbase, conf.su] call: dict[str, Callable[[bare.bot, str, str, str], None]] = { @@ -270,4 +316,6 @@ call: dict[str, Callable[[bare.bot, str, str, str], None]] = { "version": version, "np": fmpull, "markov": markov, + "setStatus": setStatus, + "getStatus": getStatus, }