view plugins/xxnamesound.py @ 121:496dbf12a6cb alpha

Traipse Alpha 'OpenRPG' {091030-00} 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 (Cleaning up for Beta): Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree {091029} Changes made to server to start working with Element Tree. Changes made to Meta Server Lib. Prepping test work for a multi meta network page. Minor bug fixed with mini to gametree Zoom Mouse plugin added. {091030} Getting ready for Beta. Server needs debugging so Alpha remains bugged. Plugin UI code cleaned. Auto start works with a graphic, pop-up asks to enable or disable plugin. Update Manager now has a partially working Status Bar. Status Bar captures terminal text, so Merc out put is visible. Manifest.xml file, will be renamed, is now much cleaner. Debug Console has a clear button and a Report Bug button. Prep work for a Term2Win class in Debug Console. Known: Current Alpha fails in Windows.
author sirebral
date Fri, 30 Oct 2009 22:21:40 -0500
parents c54768cffbd4
children
line wrap: on
line source

import os
import orpg.pluginhandler
from orpg.dirpath import dir_struct
import re
import string
from orpg.orpgCore import component

class Plugin(orpg.pluginhandler.PluginHandler):
    # Initialization subroutine.
    #
    # !self : instance of self
    # !openrpg : instance of the the base openrpg control
    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 = 'Name Sound'
        self.author = 'mDuo13'
        self.help = "This plays a 'hey!' sound whenever your name is said in chat. It is\n"
        self.help += "not HTML- or case-sensitive. You can also create nicknames to which the plugin\n"
        self.help += "will also respond. To add a nickname, type '/xxnick add *name*', where *name*\n"
        self.help += "is the nickname you want to add. Then, whenever *name* is said in chat, you'll\n"
        self.help += "hear the sound also. You can remove your nicknames by typing\n"
        self.help += "'/xxnick del*name*' where *name* is the nickname you wish to delete. Neither is\n"
        self.help += "case sensitive. Additionally, you can see what nicknames you currently have\n"
        self.help += "with '/xxnick list'."

        self.antispam = 0
        self.names = []
        self.soundfile = ''
        self.soundplayer = ''
        self.notify = False


    def plugin_enabled(self):
        self.plugin_addcommand('/xxnick', self.on_xxnick, 'add name|del name|list - This is the command for the namesound plugin')
        self.plugin_addcommand('/wnotify', self.on_wnotify, 'This will toggle notification on incoming whispers')
        self.plugin_addcommand('/sfile', self.on_sfile, 'This will set the sound file to use for notification')

        self.names = self.plugindb.GetList("xxnamesound", "names", [])

        self.soundplayer = self.sound_player = component.get('sound')

        tmp = self.plugindb.GetString('xxnamesound', 'wnotify', str(self.notify))
        if tmp == 'True':
            self.on_wnotify(None)

        self.soundfile = self.plugindb.GetString('xxnamesound', 'soundfile', dir_struct['plugins'] + 'heya.wav')


        reg = []

        if not self.chat.html_strip(self.session.name.lower()) in self.names:
            self.names.append(self.chat.html_strip(self.session.name.lower()))

        for name in self.names:
            reg.append("(?<![a-zA-Z0-9>/\#\-])" + name + "(?!\w+|[<])")

        reg = string.join(reg, "|")
        self.nameReg = re.compile(reg, re.I)


    def plugin_disabled(self):
        self.plugin_removecmd('/xxnick')
        self.plugin_removecmd('/wnotify')
        self.plugin_removecmd('/sfile')


    def on_wnotify(self, cmdargs):
        self.notify = not self.notify

        self.plugindb.SetString('xxnamesound', 'wnotify', str(self.notify))

        if self.notify:
            self.chat.InfoPost("Whisper Notification is On!")
        else:
            self.chat.InfoPost("Whisper Notification is Off!")


    def on_sfile(self, cmdargs):
        self.soundfile = cmdargs
        self.plugindb.SetString('xxnamesound', 'soundfile', cmdargs)

    def on_xxnick(self, cmdargs):
        args = cmdargs.split(None,-1)
        reg = []
        if len(args):
            name = cmdargs[len(args[0])+1:].lower().strip()

        if len(args) == 0 or args[0] == 'list':
            name_list = ''
            i = 0
            for name in self.names:
                name_list += name
                if i < len(self.names)-1:
                    name_list += ', '
                i += 1
            self.chat.InfoPost('Currently chacking for ' + name_list)
        elif args[0] == 'add':
            if name not in self.names and name != '':
                self.names.append(name)
                self.plugindb.SetList('xxnamesound', 'names', self.names)
                self.chat.InfoPost('The name ' + name + ' has been added to your nickname list. You will now hear a sound when someone says it in chat.')
            else:
                self.chat.InfoPost('The name ' + name + ' is already in your nickname list.')
        elif args[0] == 'del':
            if name in self.names:
                self.names.remove(name)
                self.plugindb.SetList('xxnamesound', 'names', self.names)
                self.chat.InfoPost('The name ' + name + ' has been removed from your nickname list.')
            else:
                self.chat.InfoPost('The name ' + name + ' is not in your nickname list.')

        for name in self.names:
            reg.append("(?<![a-zA-Z0-9>/\#\-])" + name + "['s]*(?!\w+|[<])")

        reg = string.join(reg, "|")
        self.nameReg = re.compile(reg, re.I)

    def plugin_incoming_msg(self, text, type, name, player):
        if self.antispam > 0:
            return text, type, name

        if self.nameReg.search(self.chat.html_strip(text.lower())) != None:
            self.soundplayer.play(self.soundfile)
            self.antispam = 1
        elif self.notify and type == 2:
            self.soundplayer.play(self.soundfile)
            self.antispam = 1


        return text, type, name

    def refresh_counter(self):
        #This is called once per second. That's all you need to know.
        if self.antispam:
            self.antispam -= 0.04