From 1e42493910814dd0974fbb28c5d4397c9865e93f Mon Sep 17 00:00:00 2001 From: khuxkm fbexl Date: Mon, 24 Jun 2019 00:23:26 -0400 Subject: [PATCH] Re-implement commands in the plugin system --- commands/admin.py | 19 +++++++++++++++++++ commands/botlist.py | 5 +++++ commands/fortune.py | 8 ++++++++ commands/latest.py | 21 +++++++++++++++++++++ commands/reload.py | 5 +++++ commands/roster.py | 12 ++++++++++++ 6 files changed, 70 insertions(+) create mode 100644 commands/admin.py create mode 100644 commands/botlist.py create mode 100644 commands/fortune.py create mode 100644 commands/latest.py create mode 100644 commands/reload.py create mode 100644 commands/roster.py diff --git a/commands/admin.py b/commands/admin.py new file mode 100644 index 0000000..8bf1dce --- /dev/null +++ b/commands/admin.py @@ -0,0 +1,19 @@ +import plugin + +@plugin.group("admin") +def admin(self,channel,nick,subcmd,*args): + if not self.is_admin: return True + if subcmd not in "down check".split(): return True + return False + +@admin.command("down") +def admin_down(self,channel,nick,subcmd,*args): + self.tasks.stop() + self.tasks.save_state(0) + self._bot.die("Stopping...") + sys.exit(0) + +@admin.command("check") +def admin_check(self,channel,nick,subcmd,*args): + self.say(channel,"This would check the RSS feed but I don't wanna spam") +# self.tasks.states[0] = self.check_rss(self.tasks.states[0],self.tasks.base_state) diff --git a/commands/botlist.py b/commands/botlist.py new file mode 100644 index 0000000..04ae0d0 --- /dev/null +++ b/commands/botlist.py @@ -0,0 +1,5 @@ +import plugin + +@plugin.command("botlist") +def on_botlist(self,channel,nick,*args): + self.say(channel,nick+": Maintainer: khuxkm@cosmic.voyage | Utility bot") diff --git a/commands/fortune.py b/commands/fortune.py new file mode 100644 index 0000000..99cba60 --- /dev/null +++ b/commands/fortune.py @@ -0,0 +1,8 @@ +import plugin, subprocess + +@plugin.command("fortune") +def on_fortune(self,channel,nick,*args): + output = subprocess.check_output(["/usr/games/fortune"]).decode("ascii").split("\n") + output = filter(None,output) + for line in output: + self.say(channel,"{}".format(line)) diff --git a/commands/latest.py b/commands/latest.py new file mode 100644 index 0000000..0cf0a3d --- /dev/null +++ b/commands/latest.py @@ -0,0 +1,21 @@ +import plugin, re + +@plugin.command("latest","") +def on_latest(self,channel,nick,count="5"): + if re.match(r"\d+",count): + count = int(count) + if count < 1: + count = 1 # ...nice try, smartass + if count > 5: + count = 5 # don't spam the channel + self.say(channel, "{}: Latest {} {}. (See cosmic.voyage for more!)".format(nick, count, (count == 1 and "entry" or "entries"))) + else: + self.say(channel, "{}: Latest entries matching '{}'. (See cosmic.voyage for more!)".format(nick, count)) +# output = subprocess.check_output(["/usr/local/bin/latest",str(count)]).decode("ascii").split("\n") + if type(count)==int: + output = ["Excelsior - The one khuxkm has to write {!s}".format(x+1) for x in range(count)] + else: + output = ["Your filter was {!s}".format(count)] + output = filter(None,output) + for line in output: + self.say(channel,"{}: {}".format(nick,line)) diff --git a/commands/reload.py b/commands/reload.py new file mode 100644 index 0000000..e248040 --- /dev/null +++ b/commands/reload.py @@ -0,0 +1,5 @@ +import plugin + +@plugin.command("reload","") +def reloadPlugins(bot,channel,nick,*args): + if bot.is_admin: bot.load_modules() diff --git a/commands/roster.py b/commands/roster.py new file mode 100644 index 0000000..e5fa022 --- /dev/null +++ b/commands/roster.py @@ -0,0 +1,12 @@ +import plugin, re + +unhighlight_nick = lambda nick: "_{!s}_".format(nick) + +@plugin.command("roster","") +def on_roster(self,channel,nick,*namecnt): +# output = subprocess.check_output(["/usr/local/bin/roster",' '.join(namecnt)]).decode("ascii").split("\n") + output = ["khuxkm\tExcelsior","","alexis\tVoortrekker"] + output = filter(None,output) + for line in output: + line = re.sub("\s+"," ",line).split(" ",1) + self.say(channel,"{}: {} (by {})".format(nick,line[1],unhighlight_nick(line[0])))