From Thundering Parakeet, 13 Years ago, written in Plain Text.
Embed
  1. # Supybot Development plugin
  2. # Copyright (c) 2012, Aha2Y
  3. # All rights reserved.
  4. import random
  5. import os
  6. import subprocess
  7. import supybot.utils as utils
  8. from supybot.commands import *
  9. import supybot.plugins as plugins
  10. import supybot.ircutils as ircutils
  11. import supybot.callbacks as callbacks
  12. import supybot.ircmsgs as ircmsgs
  13. from supybot.i18n import PluginInternationalization, internationalizeDocstring
  14. import socket
  15.  
  16. _ = PluginInternationalization('X')
  17.  
  18. @internationalizeDocstring
  19. class X(callbacks.Plugin):
  20.     """The playground from Aha2Y"""
  21.     threaded = True
  22. # Begin of functions
  23.  
  24.     # Random number generator
  25.     def rnumber(self, irc, msg, args, max):
  26.         """<number> - Generate pseudo-random numbers"""
  27.         if max > 1000000:
  28.             irc.reply("You may want to lower your value.")
  29.         else :
  30.             number = random.randint(1, max)
  31.             irc.reply("Random number between 0 and %s = %s" % (max, number))
  32.     rnumber = wrap(rnumber, ['positiveInt'])
  33.    
  34.     # Read the fucking manual
  35.     def rtfm(self, irc, msg, args):
  36.         """READ THE FUCKING MANUAL"""    
  37.         irc.reply("READ THE FUCKING MANUAL: http://www.irchelp.org/irchelp/rfc/rfc.html", prefixNick=False)
  38.     rtfm = wrap(rtfm)  
  39.    
  40.     # Is it up, Website checker.
  41.     def isup(self, irc, msg, args, url):
  42.        """<URL> - Is the website up or down?"""
  43.        if "http://" in url:
  44.           irc.reply("Error: Please remove the http:// part.")
  45.        else:
  46.           host = url
  47.           port = 80
  48.           checksock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  49.           try:
  50.               checksock.connect((host, port))
  51.               checksock.shutdown(2)
  52.               irc.reply("%s == online" % url)
  53.           except:
  54.               irc.reply("%s != online" % url)
  55.     isup = wrap(isup, ['TEXT'])
  56.    
  57.     #Color spam 1 (Foreground only)
  58.     def spam1(self, irc, msg, args, text):
  59.         color1 = random.randint(03, 14)
  60.         irc.reply("%s%s" % (color1, text), prefixNick=False)
  61.     spam1 = wrap(spam1, ['TEXT'])
  62.  
  63.     #Color spam 2 (Foreground, Background)
  64.     def spam2(self, irc, msg, args, text):
  65.         color1 = random.randint(03, 14)
  66.         color2 = random.randint(03, 14)
  67.         irc.reply("%s,%s%s" % (color1, color2, text), prefixNick=False)
  68.     spam2 = wrap(spam2, ['TEXT'])
  69.    
  70.     #Return ram info
  71.     def ram(self, irc, msg, args):
  72.         p = subprocess.Popen(["free", "-o"], stdout=subprocess.PIPE)
  73.         out, err = p.communicate()
  74.         out = out.split()
  75.         total = float(out[7])/1024.0/1024.0
  76.         using = float(out[8])/1024.0/1024.0
  77.         free  = float(out[9])/1024.0/1024.0
  78.         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)
  79.     ram = wrap(ram)
  80.  
  81.     def __init__(self, irc):
  82.         self.__parent = super(Test, self)
  83.         self.__parent.__init__(irc)
  84.         self.NScheck = {}
  85.  
  86.     def doNotice(self, irc, msg):
  87.         if msg.nick != "NickServ": return
  88.         if not msg.args[1].startswith("STATUS"): return
  89.        
  90.         r = msg.args[1].split()
  91.         nick = r[1]
  92.         status = int(r[2])
  93.         (irc, msg) = self.NScheck.pop(nick)
  94.        
  95.         a = {
  96.              0: "%s is not online, or not registered.",
  97.              1: "%s is not identified",
  98.              2: "%s is identified by Cert",
  99.              3: "%s is identified by password"
  100.             }
  101.        
  102.         msg = a[status] % nick
  103.         irc.reply(msg)
  104.  
  105.     def checknick(self, irc, msg, args, nick):
  106.         self.NScheck[nick] = (irc, msg)
  107.         irc.queueMsg(ircmsgs.privmsg("NickServ", "STATUS %s" % nick))
  108.     checknick = wrap(checknick, ['nick'])
  109.                
  110. #End of functions
  111.  
  112. Class = X
  113.  
  114. # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
  115.