- # Supybot Development plugin
- # Copyright (c) 2012, Aha2Y
- # All rights reserved.
- import random
- import os
- import subprocess
- import supybot.utils as utils
- from supybot.commands import *
- import supybot.plugins as plugins
- import supybot.ircutils as ircutils
- import supybot.callbacks as callbacks
- import supybot.ircmsgs as ircmsgs
- from supybot.i18n import PluginInternationalization, internationalizeDocstring
- import socket
- _ = PluginInternationalization('X')
- @internationalizeDocstring
- class X(callbacks.Plugin):
- """The playground from Aha2Y"""
- threaded = True
- # Begin of functions
- # Random number generator
- def rnumber(self, irc, msg, args, max):
- """<number> - Generate pseudo-random numbers"""
- if max > 1000000:
- irc.reply("You may want to lower your value.")
- else :
- number = random.randint(1, max)
- irc.reply("Random number between 0 and %s = %s" % (max, number))
- rnumber = wrap(rnumber, ['positiveInt'])
- # Read the fucking manual
- def rtfm(self, irc, msg, args):
- """READ THE FUCKING MANUAL"""
- irc.reply("READ THE FUCKING MANUAL: http://www.irchelp.org/irchelp/rfc/rfc.html", prefixNick=False)
- rtfm = wrap(rtfm)
- # Is it up, Website checker.
- def isup(self, irc, msg, args, url):
- """<URL> - Is the website up or down?"""
- if "http://" in url:
- irc.reply("Error: Please remove the http:// part.")
- else:
- host = url
- port = 80
- checksock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- checksock.connect((host, port))
- checksock.shutdown(2)
- irc.reply("%s == online" % url)
- except:
- irc.reply("%s != online" % url)
- isup = wrap(isup, ['TEXT'])
- #Color spam 1 (Foreground only)
- def spam1(self, irc, msg, args, text):
- color1 = random.randint(03, 14)
- irc.reply("%s%s" % (color1, text), prefixNick=False)
- spam1 = wrap(spam1, ['TEXT'])
- #Color spam 2 (Foreground, Background)
- def spam2(self, irc, msg, args, text):
- color1 = random.randint(03, 14)
- color2 = random.randint(03, 14)
- irc.reply("%s,%s%s" % (color1, color2, text), prefixNick=False)
- spam2 = wrap(spam2, ['TEXT'])
- #Return ram info
- def ram(self, irc, msg, args):
- p = subprocess.Popen(["free", "-o"], stdout=subprocess.PIPE)
- out, err = p.communicate()
- out = out.split()
- total = float(out[7])/1024.0/1024.0
- using = float(out[8])/1024.0/1024.0
- free = float(out[9])/1024.0/1024.0
- irc.reply("Total: {0:.1f} GB | Used:04 {1:.1f} GB ({2:.2%}) | Free:03 {3:.1f} GB ({4:.2%})".format(total, using, using/total, free, free/total), prefixNick=False)
- ram = wrap(ram)
- def __init__(self, irc):
- self.__parent = super(Test, self)
- self.__parent.__init__(irc)
- self.NScheck = {}
- def doNotice(self, irc, msg):
- if msg.nick != "NickServ": return
- if not msg.args[1].startswith("STATUS"): return
- r = msg.args[1].split()
- nick = r[1]
- status = int(r[2])
- (irc, msg) = self.NScheck.pop(nick)
- a = {
- 0: "%s is not online, or not registered.",
- 1: "%s is not identified",
- 2: "%s is identified by Cert",
- 3: "%s is identified by password"
- }
- msg = a[status] % nick
- irc.reply(msg)
- def checknick(self, irc, msg, args, nick):
- self.NScheck[nick] = (irc, msg)
- irc.queueMsg(ircmsgs.privmsg("NickServ", "STATUS %s" % nick))
- checknick = wrap(checknick, ['nick'])
- #End of functions
- Class = X
- # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: