comparison plugins/xxurl2link.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 15488fe94f52 81d0bfd5e800
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 import os
2 import orpg.pluginhandler
3 import re
4
5 class Plugin(orpg.pluginhandler.PluginHandler):
6 # Initialization subroutine.
7 #
8 # !self : instance of self
9 # !chat : instance of the chat window to write to
10 def __init__(self, plugindb, parent):
11 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
12
13 # The Following code should be edited to contain the proper information
14 self.name = 'URL to link conversion'
15 self.author = 'tdb30 tbaleno@wrathof.com'
16 self.help = "This plugin automaticaly wraps urls in link tags\n"
17 self.help += "making them clickable."
18
19 self.url_regex = None
20 self.mailto_regex = None
21
22 def plugin_enabled(self):
23 #This is where you set any variables that need to be initalized when your plugin starts
24 self.url_regex = re.compile("(?<![\[=\"a-z0-9:/.])((?:http|ftp|gopher)://)?(?<![@a-z])((?:[a-z0-9\-]+[-.]?[a-z0-9]+)*\.(?:[a-z]{2,4})(?:[a-z0-9_=\?\#\&~\%\.\-/\:\+;]*))", re.I)
25
26 self.mailto_regex = re.compile("(?<![=\"a-z0-9:/.])((?:[a-z0-9]+[_]?[a-z0-9]*)+@{1}(?:[a-z0-9]+[-.]?[a-z0-9]+)*\.(?:[a-z]{2,4}))", re.I)
27
28 def plugin_disabled(self):
29 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin
30 #such as closing windows created by the plugin
31 pass
32
33 def pre_parse(self, text):
34 text = self.mailto_regex.sub(self.regmailsub, text)
35 text = self.url_regex.sub(self.regurlsub, text)
36 return text
37
38 def plugin_incoming_msg(self, text, type, name, player):
39 text = self.mailto_regex.sub(self.regmailsub, text)
40 text = self.url_regex.sub(self.regurlsub, text)
41 return text, type, name
42
43 def regmailsub(self, m):
44 term = m.group(0).lower()
45 return '<a href="mailto:' + term + '">' + m.group(0) + '</a>'
46
47 def regurlsub(self, m):
48 link = m.group(2)
49 if m.group(1) != None:
50 return '<a href="' + m.group(1).lower() + link + '">' + m.group(0) + '</a>'
51 else:
52 return '<a href="http://' + link + '">' + link + '</a>'