Created
January 12, 2014 05:52
-
-
Save minecrafter/8381460 to your computer and use it in GitHub Desktop.
ramnodebot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import requests | |
import threading | |
import irc.bot | |
import irc.strings | |
class RamNodeBot(irc.bot.SingleServerIRCBot): | |
def __init__(self): | |
irc.bot.SingleServerIRCBot.__init__(self, [("espresso.netchat.io", 6667)], "ramnodebot", "ramnodebot") | |
def on_nicknameinuse(self, c, e): | |
c.nick(c.get_nickname() + "_") | |
def on_welcome(self, c, e): | |
c.join("#ramnode") | |
def on_pubmsg(self, c, e): | |
if e.arguments[0].startswith("@"): | |
cmd = e.arguments[0][1:].split(" ")[0] | |
if cmd in ['ping', 'ping6', 'traceroute', 'traceroute6', 'mtr', 'mtr6']: | |
Command(cmd, e.arguments[0][1:].split(" ")[1], c, e.source.nick).run() | |
class Command(threading.Thread): | |
def __init__(self, cmd, ip, ic, iu): | |
super(Command, self).__init__() | |
self.cmd = cmd | |
self.ip = ip | |
self.ic = ic | |
self.iu = iu | |
def run(self): | |
if self.cmd.startswith("ping"): | |
f = [self.cmd, "-c", "10", self.ip] | |
elif self.cmd == "mtr": | |
f = ["mtr", "-r", "--report-wide", self.ip] | |
elif self.cmd == "mtr6": | |
f = ["mtr", "-r", "-6", "--report-wide", self.ip] | |
else: | |
f = [self.cmd, self.ip] | |
try: | |
o = subprocess.check_output(f) | |
except subprocess.CalledProcessError: | |
return | |
self.ic.privmsg("#ramnode", | |
self.iu + ": " + requests.post("http://sprunge.us", "sprunge=" + o).text.replace("\n", "")) | |
RamNodeBot().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment