view plugins/xxsmiley.py @ 178:ff19dd30064b alpha

Traipse Alpha 'OpenRPG' {100114-02} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Keeping up with Beta) New Features: Added Bookmarks Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) Portable Mercurial Tip of the Day added, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added Dieroller structure from Core New DieRoller portability for odd Dice Added 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added Added new vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) Fixes: Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image
author sirebral
date Thu, 14 Jan 2010 12:45:14 -0600
parents c54768cffbd4
children
line wrap: on
line source

import os
import orpg.pluginhandler
from orpg.dirpath import dir_struct

class Plugin(orpg.pluginhandler.PluginHandler):
    # Initialization subroutine.
    #
    # !self : instance of self
    # !chat : instance of the chat window to write to
    def __init__(self, plugindb, parent):
        orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)

        # The Following code should be edited to contain the proper information
        self.name = 'Smilies!'
        self.author = 'mDuo13'
        self.help = "This plugin turns text smilies like >=) or :D into images. There are 15\n"
        self.help += "images. Also, you can type '/smiley' to get a list of what emoticons are\n"
        self.help += "converted to what images."

        self.smileylist = {}

    def plugin_enabled(self):
        #This is where you set any variables that need to be initalized when your plugin starts

        self.plugin_addcommand('/smiley', self.on_smiley, '- [add|remove|help] The Smiley command')

        smlist = {
                    '>:-('   :       ' <img src="' + dir_struct['plugins'] + 'images/smiley7.gif" /> ',
                    ':/'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley5.gif" /> ',
                    ':|'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley6.gif" /> ',
                    ':('     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley9.gif" /> ',
                    ' />:('  :       ' <img src="' + dir_struct['plugins'] + 'images/smiley7.gif" /> ',
                    ' />=('  :       ' <img src="' + dir_struct['plugins'] + 'images/smiley7.gif" /> ',
                    '=)'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley0.gif" /> ',
                    '=D'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley1.gif" /> ',
                    ';)'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley3.gif" /> ',
                    '=/'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley5.gif" /> ',
                    '=|'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley6.gif" /> ',
                    '=('     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley9.gif" /> ',
                    ':)'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley0.gif" /> ',
                    ':D'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley1.gif" /> ',
                    'B)'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley2.gif" /> ',
                    ':p'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley4.gif" /> ',
                    '=\\'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley5.gif" /> ',
                    ':P'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley4.gif" /> ',
                    '=P'     :       ' <img src="' + dir_struct['plugins'] + 'images/smiley4.gif" /> ',
                    '^_^'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley12.gif" /> ',
                    '^-^'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley12.gif" /> ',
                    '^.^'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley12.gif" /> ',
                    'n_n'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley12.gif" /> ',
                    'n.n'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley12.gif" /> ',
                    'n,n'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley12.gif" /> ',
                    'I-)'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley13.gif" /> ',
                    'n.n;'   :       ' <img src="' + dir_struct['plugins'] + 'images/smiley14.gif" /> ',
                    'n.n;;'  :       ' <img src="' + dir_struct['plugins'] + 'images/smiley14.gif" /> ',
                    'n_n;'   :       ' <img src="' + dir_struct['plugins'] + 'images/smiley14.gif" /> ',
                    ':-)'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley0.gif" /> ',
                    ':-D'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley1.gif" /> ',
                    ':-P'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley2.gif" /> ',
                    ':-p'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley4.gif" /> ',
                    ':-/'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley5.gif" /> ',
                    ':-|'    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley6.gif" /> ',
                    ':-('    :       ' <img src="' + dir_struct['plugins'] + 'images/smiley9.gif" /> ',
                    ':-\\'   :       ' <img src="' + dir_struct['plugins'] + 'images/smiley5.gif" /> ',
                    '-)'          :       ' <img src="' + dir_struct['plugins'] + 'images/icon_smile.gif" /> ',
                    ';-)'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_wink.gif" /> ',
                    ':->'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_smile2.gif" /> ',
                    ':-D'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_biggrin.gif" /> ',
                    ':-P'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_razz.gif" /> ',
                    ':-o'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_surprised.gif" /> ',
                    ':mrgreen:'   :       ' <img src="' + dir_struct['plugins'] + 'images/icon_mrgreen.gif" /> ',
                    ':lol:'       :       ' <img src="' + dir_struct['plugins'] + 'images/icon_lol.gif" /> ',
                    ':-('         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_sad.gif" /> ',
                    ':-|'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_neutral.gif" /> ',
                    ':-?'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_confused.gif" /> ',
                    ':-x'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_mad.gif" /> ',
                    ':shock:'     :       ' <img src="' + dir_struct['plugins'] + 'images/icon_eek.gif" /> ',
                    ':cry:'       :       ' <img src="' + dir_struct['plugins'] + 'images/icon_cry.gif" /> ',
                    ';_;'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_cry.gif" /> ',
                    ':oops:'      :       ' <img src="' + dir_struct['plugins'] + 'images/icon_redface.gif" /> ',
                    '8-)'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_cool.gif" /> ',
                    ':evil:'      :       ' <img src="' + dir_struct['plugins'] + 'images/icon_evil.gif" /> ',
                    ':twisted:'      :       ' <img src="' + dir_struct['plugins'] + 'images/icon_twisted.gif" /> ',
                    ':roll:'      :       ' <img src="' + dir_struct['plugins'] + 'images/icon_rolleyes.gif" /> ',
                    ':!:'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_exclaim.gif" /> ',
                    ':?:'         :       ' <img src="' + dir_struct['plugins'] + 'images/icon_question.gif" /> ',
                    ':idea:'      :       ' <img src="' + dir_struct['plugins'] + 'images/icon_idea.gif" /> ',
                    ':arrow:'     :       ' <img src="' + dir_struct['plugins'] + 'images/icon_arrow.gif" /> ',
                    ':ubergeek:'  :       ' <img src="' + dir_struct['plugins'] + 'images/icon_e_ugeek.gif" /> ',
                    ':geek:'      :       ' <img src="' + dir_struct['plugins'] + 'images/icon_e_geek.gif" /> ',
                    ':fairy:'    :       ' <img src="' + dir_struct['plugins'] + 'images/fairy.gif" /> ',
                    ':hood:'    :       ' <img src="' + dir_struct['plugins'] + 'images/hood.gif" /> ',
                    ':gnome:'    :       ' <img src="' + dir_struct['plugins'] + 'images/gnome.gif" /> ',
                    ':link:'    :       ' <img src="' + dir_struct['plugins'] + 'images/link.gif" /> ',
                    ':mummy:'    :       ' <img src="' + dir_struct['plugins'] + 'images/mummy.gif" /> ',
                    ':ogre:'    :       ' <img src="' + dir_struct['plugins'] + 'images/ogre.gif" /> ',
                    ':medusa:'    :       ' <img src="' + dir_struct['plugins'] + 'images/medusa.gif" /> ',
                    ':mimic:'    :       ' <img src="' + dir_struct['plugins'] + 'images/mimic.gif" /> ',
                    ':skull:'    :       ' <img src="' + dir_struct['plugins'] + 'images/skull.gif" /> ',
                    ':zombie:'    :       ' <img src="' + dir_struct['plugins'] + 'images/zombie.gif" /> ',
                    ':chocobo:'    :       ' <img src="' + dir_struct['plugins'] + 'images/chocobo.gif" /> ',
                    ':darkside:'    :       ' <img src="' + dir_struct['plugins'] + 'images/darkside.gif" /> ',
                    ':flyingspaghetti:'    :       ' <img src="' + dir_struct['plugins'] + 'images/flyingspaghetti.gif" /> ',
                    ':rupee:'    :       ' <img src="' + dir_struct['plugins'] + 'images/rupee.gif" /> ',
                    ':ros:'    :       ' <img src="' + dir_struct['plugins'] + 'images/ros.gif" /> ',
                    ':skeleton:'    :       ' <img src="' + dir_struct['plugins'] + 'images/skeleton.gif" /> ',
                    ':samurai:'    :       ' <img src="' + dir_struct['plugins'] + 'images/samurai.gif" /> '}

        self.smileylist = self.plugindb.GetDict("xxsmiley", "smileylist", smlist)

    def plugin_disabled(self):
        #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin
        #such as closing windows created by the plugin

        self.plugin_removecmd('/smiley')
        self.plugindb.SetDict("xxsmiley", "smileylist", self.smileylist)

    def on_smiley(self, cmdargs):
        #this is just an example function for a command you create create your own
        if not len(cmdargs):
            self.chat.InfoPost("Available Smilies:")
            the_list = ' <table border="1">'
            for key in self.smileylist.keys():
                the_list += ' <tr><td>' + key + ' </td><td>' + self.smileylist[key] + ' </td></tr>'
            the_list += "</table>"
            self.chat.InfoPost(the_list)
            return

        args = cmdargs.split(None, -1)

        if args[0] == 'add' and len(args) == 3:
            if args[2].find('http') > -1:
                self.smileylist[args[1]] = ' <img src="' + args[2] + '" alt="' + args[1] + '" />'
            else:
                self.smileylist[args[1]] = ' <img src="' + dir_struct["plugins"] + 'images/' + args[2] + '" />' + "\n"

            self.chat.InfoPost('Added ' + args[1] + '&nbsp&nbsp&nbsp : &nbsp&nbsp&nbsp' + self.smileylist[args[1]])

        elif args[0] == 'remove' and len(args) == 2:
            if self.smileylist.has_key(args[1]):
                del self.smileylist[args[1]]
                self.chat.InfoPost('Removed ' + args[1])
            else:
                self.chat.InfoPost(args[1] + ' was not a smiley!')

        else:
            self.chat.InfoPost('/smiley - Lists all avaliable smilies')
            self.chat.InfoPost('/smiley add {smiley} {imagefile} - Add a smily to the list. The {smiley} can be any string of text that does not contain a space. The {imagefile} should be an image in the openrpg/plugins/images directory')
            self.chat.InfoPost('/smiley remove {smiley} - Remove {smiley} from the list')

        self.plugindb.SetDict("xxsmiley", "smileylist", self.smileylist)

    def doSmiley(self, text):
        for key, value in self.smileylist.iteritems():
            text = text.replace(key, value)

        return text

    def plugin_incoming_msg(self, text, type, name, player):
        text = self.doSmiley(text)

        return text, type, name

    def post_msg(self, text, myself):
        if myself:
            text = self.doSmiley(text)

        return text