Author Topic: IrmageBoard -- X-Chat Python Script  (Read 7039 times)

0 Members and 1 Guest are viewing this topic.

Offline XVicarious

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +45/-28
  • I F**king Love Twisty Puzzles
    • View Profile
    • XVicarious
Re: IrmageBoard -- X-Chat Python Script
« Reply #15 on: November 07, 2011, 08:39:06 pm »
User input doesn't show up in the IRC channel. Its all local. The output, no, because its normal words and stuff. Just possibly altered.

EDIT: If anyone wants to write me a configuration system using xml.etree.ElementTree, please do. I've been working and I'm all fucked up...
Sample Config:
Code: [Select]
<config>
    <irc.omnimaga.org>
        <Omnimaga>
            <greentext val="0" />
            <filters val="0" />
            <filter-url val="null" />
        </Omnimaga>
        <IRP>
            <greentext val="1" />
            <filters val="1" />
            <filter-url val="http://xvicario.us/irmageboard/irp.yml" />
        </IRP>
    </irc.omnimaga.org>
</config>
And my current code...
Code: [Select]
__module_name__ = "IrmageBoard"
__module_version__ = "0.5.5"
__module_description__ = "Liek a real imageboard guies (without the images!!!1)"
tinyVersion = 55

import xchat, string, re, random, yaml, sys, os, StringIO
import xml.etree.ElementTree as ElementTree
from urllib2 import urlopen

ymlFilter = urlopen("http://xvicario.us/irmageboard/filters.yml")
myFilter = yaml.load(ymlFilter)
ymlFilter.close()
configPath = "".join([re.sub('\IrmageBoard.py$', '', os.path.realpath(__file__)),"irmageconfig.xml"])
myConfig = open(configPath)
myCfg = ElementTree.parse(myConfig)
myConfig.close()

print "\0034>>>>>",__module_name__, __module_version__, "has been loaded <<<<<\003"

def greenText(word, word_eol, userdata):
    if word_eol[0].find('>'):
        return xchat.EAT_NONE
    else:
        xchat.command(" ".join(["msg", xchat.get_info("channel"), ''.join(["3",word_eol[0]])]))
    return xchat.EAT_ALL

def filters(word, word_eol, userdata):
    newString = word_eol[0]
    for k, v in myFilter.iteritems():
        tempColor = random.randrange(0,16,1)
        tempBack = random.randrange(0,16,1)
        while (tempColor == tempBack):
            tempColor = random.randrange(0,16,1)
            tempBack = random.randrange(0,16,1)
        tempReplace = re.compile(k, re.IGNORECASE)
        newString = tempReplace.sub("".join(["\003", str(tempColor), ",", str(tempBack), v, "\003"]), newString)
    xchat.command(" ".join(["msg", xchat.get_info("channel"), newString]))
    return xchat.EAT_ALL

def irmageCommand(word, word_eol, userdata):
    try:
        if word[1] == "filters":
            if word[2] == "on":
                filterHook = xchat.hook_command("", filters)
                print "\0034Filters are now on! GO AT IT!\003"
            if word[2] == "off":
                xchat.unhook(filterHook)
                print "\0034You turned filters off :(\003"
        if word[1] == "log":
            log = urlopen("http://xvicario.us/irmageboard/log.txt")
            print log.read()
            log.close()
        if word[1] == "about":
            print __module_name__," v",__module_version__,"\nWritten by Brian J Maurer (XVicario.us, contact at [email protected])\nThis plugin adds features to XChat like an imageboard's \"\0033>greentext\003\" and filters (like when you type \"jew\" it turns into \"\0035,3Steve Jobs\003\". Many more features are to come :D"
        if word[1] == "update":
            if word[2] == "filter":
                print "\0034Updating Filters...\003"
                global ymlFilter
                ymlFilter = urlopen("http://xvicario.us/irmageboard/filters.yml")
                global myFilter
                myFilter = yaml.load(ymlFilter)
                ymlFilter.close()
                print "\0034Filters are Updated!\003"
            """
            if word[2] == "script":
                myversion = urlopen("http://xvicario.us/irmageboard/version")
                myversion = int(myversion.read())
                if (myversion == tinyVersion):
                    print "\0034NO UPDATE FOUND!\003"
                elif (myversion > tinyVersion):
                    print "\0034UPDATE FOUND!\003"
                    print "\0034Downloading Update...\003"
                    update = urlopen("http://xvicario.us/irmageboard/update")
                    update = update.read()
                    irmageBoard = open("IrmageBoard.py","w")
                    irmageBoard.write(update)
                    irmageBoard.close()
                    print "\0034Update Successful!\003"
                else:
                    print "\0034ARE YOU FROM THE FUTURE!?\003"
            """
        if word[1] == "dump":
            global myCfg
            myCfg2 = ElementTree.tostring(myCfg)
            print myCfg
            print xchat.get_info("server")
        if word[1] == "add":
            if word[2] == "server":
                myConfig = open("".join([re.sub('\IrmageBoard.py$', '', os.path.realpath(configPath))]),"r+")
                ircfg = myConfig.read()
                ircfg = ElementTree.XML(ircfg)
                newServer = ElementTree.Element(xchat.get_info("server"))
                ircfg.append(newServer)
                cfgFile = StringIO.StringIO()
                ircfg = ElementTree.tostring(ircfg)
                print type(ircfg), ircfg
                ircfg = cfgFile.write(ircfg)
                ircfg = ElementTree.parse(ircfg)
                ircfg.write(myConfig)
                myConfig.close()
    except IndexError:
        print "\0034Welcome to the IrmageBoard Plugin!  For a brief help type '/help irmage'.\003"
    return xchat.EAT_ALL
   
def facepalm(word, word_eol, userdata):
    xchat.command("ME facepalms at " + word_eol[1])
    xchat.EAT_ALL

# Hook the commands :D
xchat.hook_command("IRMAGE", irmageCommand, help="Usage:\n/irmage filters <on/off>  --  Turn the filters on or off\n/irmage log  --  Display the changelog of the plugin (downloaded from XVicario.us)\n/irmage about  --  Display an about text\n/irmage update filter  --  update the list of word filters, when you load the script you will automatically have this, but if something changes when the script is loaded, just run this and you have the new filtes ;D")
xchat.hook_command("", filters)
xchat.hook_command("", greenText)
xchat.hook_command("facepalm",facepalm)
« Last Edit: November 07, 2011, 08:42:15 pm by jkag »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: IrmageBoard -- X-Chat Python Script
« Reply #16 on: November 19, 2011, 02:45:11 pm »
Well I meant so if someone messages the bot a command about 1000 times in a row, it doesn't flood the hell out of IRC channels, causing your bot to be K-lined from efnet and stuff for spamming. Some people really don't know when to stop when they start having fun with something on IRC. Eg: Runer112 z80 commands will /ignore an user for one minute if that user uses !z80 more than 3 times a minute.

Offline XVicarious

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +45/-28
  • I F**king Love Twisty Puzzles
    • View Profile
    • XVicarious
Re: IrmageBoard -- X-Chat Python Script
« Reply #17 on: May 12, 2012, 12:54:58 am »
Ah I see what you mean (it has been quite a while lol). It isn't a bot, but a local script that is run in your and only your instance of X-Chat.  the only things that someone outside would see are the effects of the filters or greentext. (or the facepalm command)