forked from hackyourlife/lima-gold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrt.py
executable file
·106 lines (100 loc) · 4.88 KB
/
rt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/python
# -*- coding: utf-8 -*-
# vim:set ts=8 sts=8 sw=8 tw=80 noet cc=80:
# THIS IS A TEST FILE!
# The following program demostrates some of the Reg-Echses' powers:
# 000000-000001 defines a new command /kuh as an alias for /q
# 000003-000005 inflates a single # to 10 # with a loop
# 000006-000037 defines a new command /rot13
import rp
#program = [
# ('^/kuh\s*$', '/echo missing argument'), # 000000
# ('^/kuh (.*)$', r'/q \1'), # 000001
# (r'\+', r'\$'), # 000002
# (r'^(#+)$', '$-6'), # 000003
# (r'^(#+)$', r'\1#'), # 000004
# (r'^#{10}$', '$-4'), # 000005
# ('^/rot13\s*', '$-38'), # 000006
# ('^/rot13\s*$', '/echo missing argument'), # 000007
# ('^/rot13\s*', r'/rot13 ¸'), # 000008
# ('^(/rot13 .*)¸a(.*)$', r'\1˞n\2'), # 000009
# ('^(/rot13 .*)¸b(.*)$', r'\1˞o\2'), # 000010
# ('^(/rot13 .*)¸c(.*)$', r'\1˞p\2'), # 000011
# ('^(/rot13 .*)¸d(.*)$', r'\1˞q\2'), # 000012
# ('^(/rot13 .*)¸e(.*)$', r'\1˞r\2'), # 000013
# ('^(/rot13 .*)¸f(.*)$', r'\1˞s\2'), # 000014
# ('^(/rot13 .*)¸g(.*)$', r'\1˞t\2'), # 000015
# ('^(/rot13 .*)¸h(.*)$', r'\1˞u\2'), # 000016
# ('^(/rot13 .*)¸i(.*)$', r'\1˞v\2'), # 000017
# ('^(/rot13 .*)¸j(.*)$', r'\1˞w\2'), # 000018
# ('^(/rot13 .*)¸k(.*)$', r'\1˞x\2'), # 000019
# ('^(/rot13 .*)¸l(.*)$', r'\1˞y\2'), # 000020
# ('^(/rot13 .*)¸m(.*)$', r'\1˞z\2'), # 000021
# ('^(/rot13 .*)¸n(.*)$', r'\1˞a\2'), # 000022
# ('^(/rot13 .*)¸o(.*)$', r'\1˞b\2'), # 000023
# ('^(/rot13 .*)¸p(.*)$', r'\1˞c\2'), # 000024
# ('^(/rot13 .*)¸q(.*)$', r'\1˞d\2'), # 000025
# ('^(/rot13 .*)¸r(.*)$', r'\1˞e\2'), # 000026
# ('^(/rot13 .*)¸s(.*)$', r'\1˞f\2'), # 000027
# ('^(/rot13 .*)¸t(.*)$', r'\1˞g\2'), # 000028
# ('^(/rot13 .*)¸u(.*)$', r'\1˞h\2'), # 000029
# ('^(/rot13 .*)¸v(.*)$', r'\1˞i\2'), # 000030
# ('^(/rot13 .*)¸w(.*)$', r'\1˞j\2'), # 000031
# ('^(/rot13 .*)¸x(.*)$', r'\1˞k\2'), # 000032
# ('^(/rot13 .*)¸y(.*)$', r'\1˞l\2'), # 000033
# ('^(/rot13 .*)¸z(.*)$', r'\1˞m\2'), # 000034
# ('^(/rot13 .*)[¸˞](.)(.*)$', r'\1\2¸\3'), # 000035
# ('^(/rot13 .*)¸$', '$-9'), # 000036
# ('^/rot13 (.*)¸$', r'/say \1') # 000037
# ]
# This program only implements a /rot13 command for lower case letters, that can
# be used in conjunction with a /p, /e or /q command.
# If you want to use this in the client, just copy the json output and write it
# in the config file like this:
# [regex_programs]
# default = <the-json-text>
program = [
('^(?:/[peq] |/echo )?/rot13\s*', '$-35'), # 000000
('^(?:/[peq] |/echo )?/rot13\s*$', '/echo missing argument'), # 000001
('^(/[peq] )?/rot13\s*', r'\1/rot13 ¸'), # 000002
('^/echo /rot13\s*', r'/z /rot13 ¸'), # 000003
('^((?:/[peqz] )?/rot13 .*)¸a(.*)$', r'\1˞n\2'), # 000004
('^((?:/[peqz] )?/rot13 .*)¸b(.*)$', r'\1˞o\2'), # 000005
('^((?:/[peqz] )?/rot13 .*)¸c(.*)$', r'\1˞p\2'), # 000006
('^((?:/[peqz] )?/rot13 .*)¸d(.*)$', r'\1˞q\2'), # 000007
('^((?:/[peqz] )?/rot13 .*)¸e(.*)$', r'\1˞r\2'), # 000008
('^((?:/[peqz] )?/rot13 .*)¸f(.*)$', r'\1˞s\2'), # 000009
('^((?:/[peqz] )?/rot13 .*)¸g(.*)$', r'\1˞t\2'), # 000010
('^((?:/[peqz] )?/rot13 .*)¸h(.*)$', r'\1˞u\2'), # 000011
('^((?:/[peqz] )?/rot13 .*)¸i(.*)$', r'\1˞v\2'), # 000012
('^((?:/[peqz] )?/rot13 .*)¸j(.*)$', r'\1˞w\2'), # 000013
('^((?:/[peqz] )?/rot13 .*)¸k(.*)$', r'\1˞x\2'), # 000014
('^((?:/[peqz] )?/rot13 .*)¸l(.*)$', r'\1˞y\2'), # 000015
('^((?:/[peqz] )?/rot13 .*)¸m(.*)$', r'\1˞z\2'), # 000016
('^((?:/[peqz] )?/rot13 .*)¸n(.*)$', r'\1˞a\2'), # 000017
('^((?:/[peqz] )?/rot13 .*)¸o(.*)$', r'\1˞b\2'), # 000018
('^((?:/[peqz] )?/rot13 .*)¸p(.*)$', r'\1˞c\2'), # 000019
('^((?:/[peqz] )?/rot13 .*)¸q(.*)$', r'\1˞d\2'), # 000020
('^((?:/[peqz] )?/rot13 .*)¸r(.*)$', r'\1˞e\2'), # 000021
('^((?:/[peqz] )?/rot13 .*)¸s(.*)$', r'\1˞f\2'), # 000022
('^((?:/[peqz] )?/rot13 .*)¸t(.*)$', r'\1˞g\2'), # 000023
('^((?:/[peqz] )?/rot13 .*)¸u(.*)$', r'\1˞h\2'), # 000024
('^((?:/[peqz] )?/rot13 .*)¸v(.*)$', r'\1˞i\2'), # 000025
('^((?:/[peqz] )?/rot13 .*)¸w(.*)$', r'\1˞j\2'), # 000026
('^((?:/[peqz] )?/rot13 .*)¸x(.*)$', r'\1˞k\2'), # 000027
('^((?:/[peqz] )?/rot13 .*)¸y(.*)$', r'\1˞l\2'), # 000028
('^((?:/[peqz] )?/rot13 .*)¸z(.*)$', r'\1˞m\2'), # 000029
('^((?:/[peqz] )?/rot13 .*)[¸˞](.)(.*)$', r'\1\2¸\3'), # 000030
('^((?:/[peqz] )?/rot13 .*)¸$', '$-4'), # 000031
('^/rot13 (.*)¸$', r'/say \1'), # 000032
('^(/[peq]) /rot13 (.*)¸$', r'\1 \2'), # 000033
('^/z /rot13 (.*)¸$', r'/echo \1') # 000034
]
import json
print(json.dumps(program))
p = rp.compile(program)
for text in [ "/kuh", "/kuh ", "/echo bla", "/ku bla", "/kuh bla",
"eine /kuh macht muh", "+", "#", "/rot13",
"/rot13 hello, world!", "/p /rot13 blah",
"/echo /rot13 xnhqrejryfpu", "/z /rot13 blah"]:
print("'%s' -> '%s'" % (text, rp.run(p, text)))