From c96351df0b789c0975b86b84484e13019ac70bb5 Mon Sep 17 00:00:00 2001 From: pocketjawa Date: Fri, 24 Feb 2017 20:22:55 -0500 Subject: [PATCH] Add command to get UPS status --- helpcommand.txt | 3 ++- pocketbot.py | 13 ++++++++++++- ups_status.sh | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 ups_status.sh diff --git a/helpcommand.txt b/helpcommand.txt index 6ba0226..69dbc8d 100644 --- a/helpcommand.txt +++ b/helpcommand.txt @@ -5,4 +5,5 @@ Here is the the list of possible commands at this point in time: !sleep: sleep for like 5 seconds for some reason !pokeme: make the bot poke you gently !switch: display time until the switch comes out! -!wtf: Don't use unless you want a wall of copypasta \ No newline at end of file +!wtf: Don't use unless you want a wall of copypasta +!ups: Print the status of the main UPS. Updated once a minute. \ No newline at end of file diff --git a/pocketbot.py b/pocketbot.py index 97eaf6c..4084b78 100644 --- a/pocketbot.py +++ b/pocketbot.py @@ -13,6 +13,14 @@ bot_channel_id = discord.Object(id=config.get("configuration", "bot_channel_id") client = discord.Client() +#Subroutine to get UPS Status +@asyncio.coroutine +def ups_check(): + while not client.is_closed: + yield from asyncio.create_subprocess_exec("/bin/bash", "/srv/discord-pocketbot/ups_status.sh") + yield from asyncio.sleep(60) + + @client.event @asyncio.coroutine def on_ready(): @@ -48,7 +56,10 @@ def on_message(message): switchdelta = switchdate - now switchmsg = "<:switchl:283809380137435139>Only **%s** until the Switch comes out!<:switchr:283809391835349004>" % (switchdelta) yield from client.send_message(message.channel, switchmsg) + elif message.content.lower().startswith('!ups'): + ups_status = open("/tmp/ups_status.txt","r") + yield from client.send_message(message.channel, ups_status.read()) - +client.loop.create_task(ups_check()) client.run(token) \ No newline at end of file diff --git a/ups_status.sh b/ups_status.sh new file mode 100755 index 0000000..17d10a9 --- /dev/null +++ b/ups_status.sh @@ -0,0 +1,17 @@ +#===================================== +#ups_status.sh | +#Version 1.0 | +#Written by pocketjawa yo | +#http://twitter.com/pocketjawa | +#Do what you want (with this script) | +#'Cause a pirate is free | +#YOU ARE A PIRATE | +#===================================== + +#!/bin/sh -u +# UTF-8 (international) script header +PATH=/bin:/usr/bin ; export PATH # add /sbin and /usr/sbin if needed +umask 022 # use 077 for secure scripts +unset LC_ALL # unset the over-ride variable + +/sbin/apcaccess |egrep '^DATE|HOSTNAME|MODEL|STATUS|LOADPCT|BCHARGE|TIMELEFT' >/tmp/ups_status.txt \ No newline at end of file