Skip to content

Commit 6f5caf9

Browse files
committed
Add WTF8
1 parent 38658d2 commit 6f5caf9

File tree

8 files changed

+437
-2
lines changed

8 files changed

+437
-2
lines changed

SC2/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def sc(self, irc, msg, args, name, bnet_id):
2828

2929
if bnet_id == None:
3030
try:
31-
url = "http://sc2ranks.com/api/search/eu/%s" % (name)
31+
url = "http://sc2ranks.com/api/search/eu/%s?appKey=h4x.no" % (name)
3232
d = urllib.urlopen(url).read()
3333
except IOError, i:
3434
irc.reply("Failed searching for character %s" % (name))
@@ -47,7 +47,7 @@ def sc(self, irc, msg, args, name, bnet_id):
4747
return
4848

4949
try:
50-
url = "http://sc2ranks.com/api/char/eu/%s!%s" % (name, bnet_id)
50+
url = "http://sc2ranks.com/api/char/eu/%s!%s?appKey=h4x.no" % (name, bnet_id)
5151
d = urllib.urlopen(url).read()
5252
except IOError, i:
5353
if self.errorReported == False:

WTF8/LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Eiffel Forum License, version 2
2+
3+
1. Permission is hereby granted to use, copy, modify and/or distribute this
4+
package, provided that:
5+
* copyright notices are retained unchanged,
6+
* any distribution of this package, whether modified or not, includes
7+
this license text.
8+
2. Permission is hereby also granted to distribute binary programs which
9+
depend on this package. If the binary program depends on a modified
10+
version of this package, you are encouraged to publicly release the
11+
modified version of this package.
12+
13+
***********************
14+
15+
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT WARRANTY. ANY EXPRESS OR IMPLIED
16+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
18+
SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
20+
OF THIS PACKAGE.
21+
***********************

WTF8/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Insert a description of your plugin here, with any notes, etc. about using it.

WTF8/__init__.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
###
2+
# Copyright (c) 2008, emh
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions, and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions, and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the author of this software nor the name of
14+
# contributors to this software may be used to endorse or promote products
15+
# derived from this software without specific prior written consent.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
29+
###
30+
31+
"""
32+
Add a description of the plugin (to be presented to the user inside the wizard)
33+
here. This should describe *what* the plugin does.
34+
"""
35+
36+
import supybot
37+
import supybot.world as world
38+
39+
# Use this for the version of this plugin. You may wish to put a CVS keyword
40+
# in here if you're keeping the plugin in CVS or some similar system.
41+
__version__ = ""
42+
43+
# XXX Replace this with an appropriate author or supybot.Author instance.
44+
__author__ = supybot.authors.unknown
45+
46+
# This is a dictionary mapping supybot.Author instances to lists of
47+
# contributions.
48+
__contributors__ = {}
49+
50+
# This is a url where the most recent plugin package can be downloaded.
51+
__url__ = '' # 'http://supybot.com/Members/yourname/WTF8/download'
52+
53+
import config
54+
import plugin
55+
reload(plugin) # In case we're being reloaded.
56+
# Add more reloads here if you add third-party modules and want them to be
57+
# reloaded when this plugin is reloaded. Don't forget to import them as well!
58+
59+
if world.testing:
60+
import test
61+
62+
Class = plugin.Class
63+
configure = config.configure
64+
65+
66+
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

WTF8/codepoints.py

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/usr/bin/env python
2+
"""
3+
codepoints.py - Phenny Codepoints Module
4+
Copyright 2008, Sean B. Palmer, inamidst.com
5+
Licensed under the Eiffel Forum License 2.
6+
7+
http://inamidst.com/phenny/
8+
"""
9+
10+
import re, unicodedata
11+
from itertools import islice
12+
13+
def about(u, cp=None, name=None):
14+
if cp is None:
15+
cp = ord(u)
16+
if name is None:
17+
try: name = unicodedata.name(u)
18+
except ValueError:
19+
return 'U+%04X (No name found)' % cp
20+
21+
if not unicodedata.combining(u):
22+
template = 'U+%04X %s (%s)'
23+
else: template = 'U+%04X %s (\xe2\x97\x8c%s)'
24+
return template % (cp, name, u.encode('utf-8'))
25+
26+
def codepoint_reverse(char):
27+
arg = arg.upper()
28+
29+
#r_label = re.compile('\\b' + arg.replace(' ', '.*\\b') + '\\b')
30+
31+
results = []
32+
for cp in xrange(0xFFFF):
33+
u = unichr(cp)
34+
try: name = unicodedata.name(u)
35+
except ValueError: continue
36+
37+
if r_label.search(name):
38+
results.append((len(name), u, cp, name))
39+
if not results:
40+
r_label = re.compile('\\b' + arg.replace(' ', '.*\\b'))
41+
for cp in xrange(0xFFFF):
42+
u = unichr(cp)
43+
try: name = unicodedata.name(u)
44+
except ValueError: continue
45+
46+
if r_label.search(name):
47+
results.append((len(name), u, cp, name))
48+
49+
if results:
50+
#length, u, cp, name = sorted(results)[0]
51+
#return about(u, cp, name)
52+
for length, u, cp, name in sorted(results):
53+
yield about(u, cp, name)
54+
55+
56+
def codepoint_simple(arg):
57+
arg = arg.upper()
58+
59+
r_label = re.compile('\\b' + arg.replace(' ', '.*\\b') + '\\b')
60+
61+
results = []
62+
for cp in xrange(0xFFFF):
63+
u = unichr(cp)
64+
try: name = unicodedata.name(u)
65+
except ValueError: continue
66+
67+
if r_label.search(name):
68+
results.append((len(name), u, cp, name))
69+
if not results:
70+
r_label = re.compile('\\b' + arg.replace(' ', '.*\\b'))
71+
for cp in xrange(0xFFFF):
72+
u = unichr(cp)
73+
try: name = unicodedata.name(u)
74+
except ValueError: continue
75+
76+
if r_label.search(name):
77+
results.append((len(name), u, cp, name))
78+
79+
if results:
80+
#length, u, cp, name = sorted(results)[0]
81+
#return about(u, cp, name)
82+
for length, u, cp, name in sorted(results):
83+
yield about(u, cp, name)
84+
85+
def codepoint_extended(arg):
86+
arg = arg.upper()
87+
try: r_search = re.compile(arg)
88+
except: raise ValueError('Broken regexp: %r' % arg)
89+
90+
for cp in xrange(1, 0x10FFFF):
91+
u = unichr(cp)
92+
name = unicodedata.name(u, '-')
93+
94+
if r_search.search(name):
95+
yield about(u, cp, name)
96+
97+
def u(phenny, input):
98+
"""Look up unicode information."""
99+
arg = input.bytes[3:]
100+
# phenny.msg('#inamidst', '%r' % arg)
101+
if not arg:
102+
return phenny.reply('You gave me zero length input.')
103+
104+
# @@ space
105+
if set(arg.upper()) - set(
106+
'ABCDEFGHIJKLMNOPQRSTUVWYXYZ0123456789- .?+*{}[]\\/^$'):
107+
printable = False
108+
elif len(arg) > 1:
109+
printable = True
110+
else: printable = False
111+
112+
if printable:
113+
extended = False
114+
for c in '.?+*{}[]\\/^$':
115+
if c in arg:
116+
extended = True
117+
break
118+
119+
if len(arg) == 4:
120+
try: u = unichr(int(arg, 16))
121+
except ValueError: pass
122+
else: return phenny.say(about(u))
123+
124+
if extended:
125+
# look up a codepoint with regexp
126+
results = list(islice(codepoint_extended(arg), 4))
127+
for i, result in enumerate(results):
128+
if (i < 2) or ((i == 2) and (len(results) < 4)):
129+
phenny.say(result)
130+
elif (i == 2) and (len(results) > 3):
131+
phenny.say(result + ' [...]')
132+
if not results:
133+
phenny.reply('Sorry, no results')
134+
else:
135+
# look up a codepoint freely
136+
result = codepoint_simple(arg)
137+
if result is not None:
138+
phenny.say(result)
139+
else: phenny.reply("Sorry, no results for %r." % arg)
140+
else:
141+
text = arg.decode('utf-8')
142+
# look up less than three podecoints
143+
if len(text) <= 3:
144+
for u in text:
145+
phenny.say(about(u))
146+
# look up more than three podecoints
147+
elif len(text) <= 10:
148+
phenny.reply(' '.join('U+%04X' % ord(c) for c in text))
149+
else: phenny.reply('Sorry, your input is too long!')
150+
u.commands = ['u']
151+
u.example = '.u 203D'
152+
153+
def bytes(phenny, input):
154+
"""Show the input as pretty printed bytes."""
155+
b = input.bytes
156+
phenny.reply('%r' % b[b.find(' ') + 1:])
157+
bytes.commands = ['bytes']
158+
bytes.example = '.bytes \xe3\x8b\xa1'
159+
160+
if __name__ == '__main__':
161+
print __doc__.strip()

WTF8/config.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
###
2+
# Copyright (c) 2008, emh
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions, and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions, and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the author of this software nor the name of
14+
# contributors to this software may be used to endorse or promote products
15+
# derived from this software without specific prior written consent.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
29+
###
30+
31+
import supybot.conf as conf
32+
import supybot.registry as registry
33+
34+
def configure(advanced):
35+
# This will be called by supybot to configure this module. advanced is
36+
# a bool that specifies whether the user identified himself as an advanced
37+
# user or not. You should effect your configuration by manipulating the
38+
# registry as appropriate.
39+
from supybot.questions import expect, anything, something, yn
40+
conf.registerPlugin('WTF8', True)
41+
42+
43+
WTF8 = conf.registerPlugin('WTF8')
44+
# This is where your configuration variables (if any) should go. For example:
45+
# conf.registerGlobalValue(WTF8, 'someConfigVariableName',
46+
# registry.Boolean(False, """Help for someConfigVariableName."""))
47+
48+
49+
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

0 commit comments

Comments
 (0)