comparison plugins/xxnamesound.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children c54768cffbd4
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 import os
2 import orpg.pluginhandler
3 import orpg.dirpath
4 import re
5 import string
6 from orpg.orpgCore import open_rpg
7
8 class Plugin(orpg.pluginhandler.PluginHandler):
9 # Initialization subroutine.
10 #
11 # !self : instance of self
12 # !openrpg : instance of the the base openrpg control
13 def __init__(self, plugindb, parent):
14 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
15
16 # The Following code should be edited to contain the proper information
17 self.name = 'Name Sound'
18 self.author = 'mDuo13'
19 self.help = "This plays a 'hey!' sound whenever your name is said in chat. It is\n"
20 self.help += "not HTML- or case-sensitive. You can also create nicknames to which the plugin\n"
21 self.help += "will also respond. To add a nickname, type '/xxnick add *name*', where *name*\n"
22 self.help += "is the nickname you want to add. Then, whenever *name* is said in chat, you'll\n"
23 self.help += "hear the sound also. You can remove your nicknames by typing\n"
24 self.help += "'/xxnick del*name*' where *name* is the nickname you wish to delete. Neither is\n"
25 self.help += "case sensitive. Additionally, you can see what nicknames you currently have\n"
26 self.help += "with '/xxnick list'."
27
28 self.antispam = 0
29 self.names = []
30 self.soundfile = ''
31 self.soundplayer = ''
32 self.notify = False
33
34
35 def plugin_enabled(self):
36 self.plugin_addcommand('/xxnick', self.on_xxnick, 'add name|del name|list - This is the command for the namesound plugin')
37 self.plugin_addcommand('/wnotify', self.on_wnotify, 'This will toggle notification on incoming whispers')
38 self.plugin_addcommand('/sfile', self.on_sfile, 'This will set the sound file to use for notification')
39
40 self.names = self.plugindb.GetList("xxnamesound", "names", [])
41
42 self.soundplayer = self.sound_player = open_rpg.get_component('sound')
43
44 tmp = self.plugindb.GetString('xxnamesound', 'wnotify', str(self.notify))
45 if tmp == 'True':
46 self.on_wnotify(None)
47
48 self.soundfile = self.plugindb.GetString('xxnamesound', 'soundfile', orpg.dirpath.dir_struct['plugins'] + 'heya.wav')
49
50
51 reg = []
52
53 if not self.chat.html_strip(self.session.name.lower()) in self.names:
54 self.names.append(self.chat.html_strip(self.session.name.lower()))
55
56 for name in self.names:
57 reg.append("(?<![a-zA-Z0-9>/\#\-])" + name + "(?!\w+|[<])")
58
59 reg = string.join(reg, "|")
60 self.nameReg = re.compile(reg, re.I)
61
62
63 def plugin_disabled(self):
64 self.plugin_removecmd('/xxnick')
65 self.plugin_removecmd('/wnotify')
66 self.plugin_removecmd('/sfile')
67
68
69 def on_wnotify(self, cmdargs):
70 self.notify = not self.notify
71
72 self.plugindb.SetString('xxnamesound', 'wnotify', str(self.notify))
73
74 if self.notify:
75 self.chat.InfoPost("Whisper Notification is On!")
76 else:
77 self.chat.InfoPost("Whisper Notification is Off!")
78
79
80 def on_sfile(self, cmdargs):
81 self.soundfile = cmdargs
82 self.plugindb.SetString('xxnamesound', 'soundfile', cmdargs)
83
84 def on_xxnick(self, cmdargs):
85 args = cmdargs.split(None,-1)
86 reg = []
87 if len(args):
88 name = cmdargs[len(args[0])+1:].lower().strip()
89
90 if len(args) == 0 or args[0] == 'list':
91 name_list = ''
92 i = 0
93 for name in self.names:
94 name_list += name
95 if i < len(self.names)-1:
96 name_list += ', '
97 i += 1
98 self.chat.InfoPost('Currently chacking for ' + name_list)
99 elif args[0] == 'add':
100 if name not in self.names and name != '':
101 self.names.append(name)
102 self.plugindb.SetList('xxnamesound', 'names', self.names)
103 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.')
104 else:
105 self.chat.InfoPost('The name ' + name + ' is already in your nickname list.')
106 elif args[0] == 'del':
107 if name in self.names:
108 self.names.remove(name)
109 self.plugindb.SetList('xxnamesound', 'names', self.names)
110 self.chat.InfoPost('The name ' + name + ' has been removed from your nickname list.')
111 else:
112 self.chat.InfoPost('The name ' + name + ' is not in your nickname list.')
113
114 for name in self.names:
115 reg.append("(?<![a-zA-Z0-9>/\#\-])" + name + "['s]*(?!\w+|[<])")
116
117 reg = string.join(reg, "|")
118 self.nameReg = re.compile(reg, re.I)
119
120 def plugin_incoming_msg(self, text, type, name, player):
121 if self.antispam > 0:
122 return text, type, name
123
124 if self.nameReg.search(self.chat.html_strip(text.lower())) != None:
125 self.soundplayer.play(self.soundfile)
126 self.antispam = 1
127 elif self.notify and type == 2:
128 self.soundplayer.play(self.soundfile)
129 self.antispam = 1
130
131
132 return text, type, name
133
134 def refresh_counter(self):
135 #This is called once per second. That's all you need to know.
136 if self.antispam:
137 self.antispam -= 0.04