Omnimaga

General Discussion => Technology and Development => Computer Projects and Ideas => Topic started by: XVicarious on October 19, 2011, 08:34:53 pm

Title: IrmageBoard -- X-Chat Python Script
Post by: XVicarious on October 19, 2011, 08:34:53 pm
Hey all, I have been working on a new script called IrmageBoard and it is for X-Chat!  It is written in Python.  Here are the features:

-- >greentext
-- Filters (if you don't know what they are,  it changes words like "moot" into "missingno" , and "missingno" is colored)
-- /facepalm command (*XVicarious facepalms at Juju :P)
-- Update the filter list (stored on a webserver) without reloading the plugin with "/irmage update filter"
-- See the update log of the script with "/irmage log"

Upcoming Features:
-- Update the script with "/irmage update script"
-- Add configurations for servers and channels!

Bugs:
-- NONE! (I hope :D)

Download: http://xvicario.us/getfile.php?f=IrmageBoard.py (v0.5.0)

Development Version:
Spoiler For CODE:
Code: [Select]
NO CURRENT DEV VERSION!

You need to have PyYaml for this plugin installed!

Here is an example of a filters.yml (the first word is the word to be replaced, the second is the word to replace with)
Code: [Select]
lol : Laughing Out Loud
jkag : Pure Awesomeness :D

The readme for the next version (v0.7.0)
Spoiler For Spoiler:
Quote
------------------
IRMAGEBOARD v0.7.0
      README
------------------

IrmageBoard adds some features you see on imageboards on the internet like that of 4chan.  These features are completely useless, and just for fun! This document gives you an overview of the syntax for the plugin and its configuration files.

------------
REQUIREMENTS
------------
X-Chat with the Python Plugin
Python 2.7
PyYaml

--------
COMMANDS
--------
Note the command is in the brackets

[irmage] -- See the introduction text
[irmage log] -- See the changelog for the script
[irmage about] -- See an about screen
[irmage update <filter/script>] -- Updates the filters or script
[irmage add server] -- Adds the server you are currently on (where you executed the command) to the configuration file
[irmage add channel] -- Adds the current channel you are on to the server you are on to the configuration file
[irmage set filter <0/1>] -- Sets the filter on or off for the channel you are on
[irmage set filter-url <url>] -- Sets the location of the filter file to the configuration file of the channel you are currently on
[irmage set greentext <0/1>] -- Sets greentext on or off for the channel you are currently on


-------------
FILTER FORMAT
-------------
The filters use YAML for replacing certain words.

<word-to-replace> : <word to replace with>

Super easy to set new filters.  Just save it as a *.yml file and upload it somewhere!


--------------------
CONFIGURATION FORMAT
--------------------
The configuration uses YAML for adding servers and channels and options as well. Please note that the script can automagically add new servers and channels to this list from a simple command!

irc.ircserver.com:
    MyChannel:
        greentext: <0/1>
        filters: <0/1>
        filter-url: <url>

A very simple configuration format!


-----
LEGAL
-----
Use, improve, and abuse.  Please if you do improve it give credit to: XVicarious (Brian Maurer, [email protected]).

Also, I need suggestions on features to add to my plugin!  I know it needs more features!
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: XVicarious on October 20, 2011, 10:55:06 pm
v0.5.5 released.  Fixed the bug and added /facepalm <facepalm at this>
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: DJ Omnimaga on October 20, 2011, 11:11:19 pm
Lol nice, although at first because of the name I thought it was some sort of 4chan image board but for display in X-Chat instead of a browser. :P

Make sure people won't abuse facepalm though, because facepalming at other ppl in omni might get the command user banned x.x
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: XVicarious on October 20, 2011, 11:20:29 pm
Taht is true.  Oh and a note, most of the filters are inappropriate for Omnimaga since it was made for another server where the rules are more lax.  If you guys want, I'll host a special version of the filter for Omnimaga use.  But you have to come up with the filter ideas.
IE, lobster filters to Netham45
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: DJ Omnimaga on October 20, 2011, 11:23:04 pm
Ok it migth be best. Swearing is allowed here but if it got too bad (like two swear per sentence in average) or if there'S too much caps lock it would be a problem.
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: XVicarious on October 20, 2011, 11:42:59 pm
I know its allowed, but just the types of words I used I have never heard here, so yeah.
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: DJ Omnimaga on October 20, 2011, 11:44:56 pm
Oh ok, yeah you migth want to be careful about that. Also at some other places you gotta be careful too since you might be labelled as bigot or something even if you are just pissed at Microsoft for example. (which is even worse with the fact that a person gets pissed at M$ an average of 8 hours a day)
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: XVicarious on October 20, 2011, 11:49:09 pm
But if people want to use it here, please give me some ideas for filters here :)
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: Juju on October 21, 2011, 10:46:38 am
Why not configuring the filters per channel? So you could have one filter list for #omnimaga and one for some other channel, etc.
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: XVicarious on October 21, 2011, 09:03:33 pm
That is a good idea... I'll look into it.  It will require a configuration file... I'll just use YAML again since INI was giving me problems for XTranzlator
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: XVicarious on November 06, 2011, 08:38:24 pm
Updated first post. Added readme for the next version.
v0.7.0 is aimed for Friday, 11 November 2011! (not working at all this week, will have LOTS of time!)

(and please give me more ideas for features)
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: ruler501 on November 06, 2011, 09:39:33 pm
This is an idea that can from IRC today: Creating a /punch script


so is the filter for this like the builtin filter for XChat just with the terms stored on a server?
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: DJ Omnimaga on November 06, 2011, 10:36:17 pm
Does the script let people enable/disable individual features by the way? For example if someone doesn't want the script's racial/bigot jokes to work but still want the other stuff, or vice-versa?
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: XVicarious on November 07, 2011, 06:45:43 pm
Yes DJ_O.  You can disable certain features.  Everything is automatically off when you are on a channel.  You can also have separate filter files for each channel.
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: DJ Omnimaga on November 07, 2011, 06:47:29 pm
Good to hear. Is there also flood control for commands requiring user input?
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: XVicarious 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)
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: DJ Omnimaga 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.
Title: Re: IrmageBoard -- X-Chat Python Script
Post by: XVicarious 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)