Tue, 18 Aug 2015 14:38:54 +0300
Use python3 in the shebang
124
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
1 | ''' |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
2 | Copyright 2014-2015 Teemu Piippo |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
3 | All rights reserved. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
4 | |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
7 | are met: |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
8 | |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
15 | derived from this software without specific prior written permission. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
16 | |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
27 | ''' |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
28 | |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
29 | from __future__ import print_function |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | import os |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | import re |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
32 | import time |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
33 | import sys |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
65
diff
changeset
|
34 | from configfile import Config |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
65
20bd76353eb5
- modularized the configuration and made it more systematic
Teemu Piippo <crimsondusk64@gmail.com>
parents:
62
diff
changeset
|
36 | Modules = {} |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | Commands = {} |
118
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
38 | Hooks = {} |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | class CommandError (Exception): |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | def __init__ (self, value): |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | self.value = value |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | def __str__ (self): |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | return self.value |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | # init_data() |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | # Initializes command module data |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | def init_data(): |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | global Commands |
65
20bd76353eb5
- modularized the configuration and made it more systematic
Teemu Piippo <crimsondusk64@gmail.com>
parents:
62
diff
changeset
|
53 | global Modules |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | files = os.listdir ('.') |
118
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
55 | numHooks = 0 |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | for fn in files: |
65
20bd76353eb5
- modularized the configuration and made it more systematic
Teemu Piippo <crimsondusk64@gmail.com>
parents:
62
diff
changeset
|
58 | if fn[0:4] != 'mod_' or fn[-3:] != '.py': |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | continue |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | fn = fn[0:-3] |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | globals = {} |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | module = __import__ (fn) |
65
20bd76353eb5
- modularized the configuration and made it more systematic
Teemu Piippo <crimsondusk64@gmail.com>
parents:
62
diff
changeset
|
64 | Modules[fn] = module |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
66 | if not hasattr (module, 'ModuleData'): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
67 | continue # No manifest |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
68 | |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
69 | if 'commands' in module.ModuleData: |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
70 | for cmd in module.ModuleData['commands']: |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
71 | install_command (cmd, module) |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | |
118
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
73 | if 'hooks' in module.ModuleData: |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
74 | for key, hooks in module.ModuleData['hooks'].items(): |
118
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
75 | for hook in hooks: |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
76 | if key not in Hooks: |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
77 | Hooks[key] = [] |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
78 | |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
79 | Hooks[key].append ({'name': hook, 'func': getattr (module, hook)}) |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
80 | numHooks += 1 |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
81 | |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
82 | print ('''Loaded module %s''' % fn) |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
84 | print ('''Loaded %d commands and %d hooks in %d modules''' % |
118
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
85 | (len (Commands), numHooks, len (Modules))) |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
87 | def install_command (cmd, module): |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
88 | if cmd['args'] == None: |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
89 | cmd['args'] = '' |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
90 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
91 | Modules[module.__name__] = module |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
92 | cmd['module'] = module |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
93 | cmd['regex'] = make_regex (cmd['args']) |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
94 | cmd['argnames'] = [] |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
95 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
96 | for argname in cmd['args'].split (' '): |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
97 | argname = argname[1:-1] |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
98 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
99 | if argname[-3:] == '...': |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
100 | argname = argname[0:-3] |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
101 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
102 | if argname == '': |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
103 | continue |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
104 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
105 | cmd['argnames'].append (argname) |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
106 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
107 | Commands[cmd['name']] = cmd |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
108 | |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | # command_error (message) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | # Raises a command error |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | def command_error (message): |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | raise CommandError (message) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | # |
102
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
118 | # is_available (cmd, ident, host) |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
119 | # |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
120 | # Is the given command available to the given user? |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
121 | # |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
122 | def is_available (cmd, ident, host): |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
123 | if cmd['level'] == 'admin' \ |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
124 | and not "%s@%s" % (ident, host) in Config.get_value ('admins', default=[]): |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
125 | return False |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
126 | |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
127 | return True |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
128 | |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
129 | # |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
130 | # response_function |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
131 | # |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
132 | g_responsePages = [[]] |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
133 | g_responsePageNum = 0 |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
134 | g_lastConfirm = 0 |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
135 | g_confirmCommand = None |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
136 | |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
137 | class Confirmxeption (Exception): |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
138 | def __init__ (self, id, value): |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
139 | self.id = id |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
140 | self.message = value |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
141 | def __str__ (self): |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
142 | return self.message |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
143 | |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
144 | def response_function (message): |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
145 | global g_responsePages |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
146 | |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
147 | if len (g_responsePages[-1]) > 4: |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
148 | g_responsePages.append ([message]) |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
149 | else: |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
150 | g_responsePages[-1].append (message) |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
151 | |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
152 | def confirm_function (id, message): |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
153 | raise Confirmxeption (id, message) |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
154 | |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
155 | def print_responses (commandObject): |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
156 | global g_responsePages |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
157 | global g_responsePageNum |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
158 | bot = commandObject['bot'] |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
159 | replyto = commandObject['replyto'] |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
160 | |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
161 | # Check bounds |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
162 | if g_responsePageNum >= len (g_responsePages): |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
163 | bot.privmsg (replyto, "No more messages.") |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
164 | return |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
165 | |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
166 | # Print this page |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
167 | for line in g_responsePages[g_responsePageNum]: |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
168 | bot.privmsg (replyto, line) |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
169 | |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
170 | # Advance page cursor |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
171 | g_responsePageNum += 1 |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
172 | |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
173 | # If this was not the last page, tell the user there's more |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
174 | if g_responsePageNum != len (g_responsePages): |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
175 | num = (len (g_responsePages) - g_responsePageNum) |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
176 | bot.privmsg (replyto, "%d more page%s, use .more to continue output" \ |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
177 | % (num, 's' if num != 1 else '')) |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
178 | |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
179 | # |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
180 | # check_same_caller (comm1, comm2) |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
181 | # |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
182 | # Are the two commands called by the same person? |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
183 | # |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
184 | def check_same_caller (comm1, comm2): |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
185 | return comm1['bot'].name == comm2['bot'].name \ |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
186 | and comm1['sender'] == comm2['sender'] \ |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
187 | and comm1['ident'] == comm2['ident'] \ |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
188 | and comm1['host'] == comm2['host'] |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
189 | |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
190 | def exec_command (commandObject): |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
191 | global g_lastConfirm |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
192 | global g_confirmCommand |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
193 | |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
194 | if 'function' in commandObject['info']: |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
195 | func = commandObject['info']['function'] |
149
1759c15cd0ca
Added ability to define commands into the manifest
Teemu Piippo <tsapii@utu.fi>
parents:
146
diff
changeset
|
196 | else: |
1759c15cd0ca
Added ability to define commands into the manifest
Teemu Piippo <tsapii@utu.fi>
parents:
146
diff
changeset
|
197 | cmdname = commandObject['cmdname'] |
1759c15cd0ca
Added ability to define commands into the manifest
Teemu Piippo <tsapii@utu.fi>
parents:
146
diff
changeset
|
198 | |
1759c15cd0ca
Added ability to define commands into the manifest
Teemu Piippo <tsapii@utu.fi>
parents:
146
diff
changeset
|
199 | try: |
1759c15cd0ca
Added ability to define commands into the manifest
Teemu Piippo <tsapii@utu.fi>
parents:
146
diff
changeset
|
200 | func = getattr (commandObject['module'], 'cmd_' + cmdname) |
1759c15cd0ca
Added ability to define commands into the manifest
Teemu Piippo <tsapii@utu.fi>
parents:
146
diff
changeset
|
201 | except AttributeError: |
1759c15cd0ca
Added ability to define commands into the manifest
Teemu Piippo <tsapii@utu.fi>
parents:
146
diff
changeset
|
202 | command_error ('''command '%s' does not have a definition''' % cmdname) |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
203 | |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
204 | try: |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
205 | func (**commandObject) |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
206 | except Confirmxeption as e: |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
207 | if time.time() - g_lastConfirm < 15 and g_confirmCommand != None: |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
208 | command_error ('''another confirm is underway''') |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
209 | |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
210 | g_lastConfirm = time.time() |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
211 | response_function (str (e) + ' (.yes/.no)') |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
212 | commandObject['confirmed'] = e.id |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
213 | g_confirmCommand = commandObject |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
214 | except Exception as e: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
215 | command_error (str (e)) |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
216 | |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
217 | # |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | # call_command (bot, message, cmdname, **kvargs) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
220 | # Calls a cobalt command |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | def call_command (bot, message, cmdname, **kvargs): |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
223 | global g_responsePages |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
224 | global g_responsePageNum |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
225 | |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | try: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | cmd = Commands[cmdname] |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | except KeyError: |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
229 | print ('''No such command %s''' % cmdname) |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
230 | return |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
231 | |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
232 | if not is_available (cmd=cmd, ident=kvargs['ident'], host=kvargs['host']): |
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
233 | command_error ('''you may not use %s''' % cmdname) |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
234 | |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | match = re.compile (cmd['regex']).match (message) |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
236 | |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | if match == None: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | # didn't match |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
239 | command_error ('''usage: %s %s''' % (cmd['name'], cmd['args'])) |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
240 | |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
241 | # .more is special as it is an interface to the page system. |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
242 | # Anything else resets it. |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
243 | if cmdname != 'more': |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
244 | g_responsePages = [[]] |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
245 | g_responsePageNum = 0 |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
246 | |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | i = 1 |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | args = {} |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | for argname in cmd['argnames']: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | args[argname] = match.group (i) |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | i += 1 |
115 | 253 | |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
254 | print ('''%s was called by %s''' % (cmdname, kvargs['sender'])) |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
255 | commandObject = kvargs |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
256 | commandObject['bot'] = bot |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
257 | commandObject['cmdname'] = cmdname |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
258 | commandObject['args'] = args |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
259 | commandObject['reply'] = response_function |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
260 | commandObject['confirm'] = confirm_function |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
261 | commandObject['confirmed'] = 0 |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
262 | commandObject['commandObject'] = commandObject |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
263 | commandObject['info'] = cmd |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
264 | commandObject['module'] = cmd['module'] |
118
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
265 | commandObject['error'] = command_error |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
266 | exec_command (commandObject) |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
267 | |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
268 | # Print the first page of responses. |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
269 | if cmdname != 'more': |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
270 | print_responses (commandObject) |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
271 | |
118
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
272 | def call_hook (bot, hookname, **kvargs): |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
273 | global g_responsePages |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
274 | global g_responsePageNum |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
275 | hookObject = kvargs |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
276 | hookObject['bot'] = bot |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
277 | g_responsePages = [[]] |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
278 | g_responsePageNum = 0 |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
279 | |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
280 | if 'replyto' in hookObject: |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
281 | hookObject['reply'] = response_function |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
282 | |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
283 | if hookname in Hooks: |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
284 | for hook in Hooks[hookname]: |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
285 | hook['func'] (**hookObject) |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
286 | |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
287 | print_responses (hookObject) |
dbf49689af0d
- added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
288 | |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
289 | def confirm (cmd, yes): |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
290 | global g_confirmCommand |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
291 | |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
292 | if g_confirmCommand == None: |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
293 | cmd['reply'] ('%s to what?' % cmd['cmdname']) |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
294 | return |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
295 | |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
296 | if not check_same_caller (cmd, g_confirmCommand): |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
297 | return |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
298 | |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
299 | if yes: |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
300 | exec_command (g_confirmCommand) |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
301 | else: |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
302 | cmd['reply'] ('okay then') |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
303 | |
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
304 | g_confirmCommand = None |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | # |
102
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
307 | # get_available_commands |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
308 | # |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
309 | # Gets a list of commands available to the given user |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
310 | # |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
311 | def get_available_commands (ident, host): |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
312 | result=[] |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
313 | |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
314 | for cmdname,cmd in Commands.items(): |
102
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
315 | if not is_available (cmd, ident, host): |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
316 | continue |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
317 | |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
318 | result.append (cmdname) |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
319 | |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
320 | return result |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
321 | |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
322 | # |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
323 | # get_command_by_name |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
324 | # |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
325 | # Gets a command by name |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
326 | # |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
327 | def get_command_by_name (name): |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
328 | try: |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
329 | return Commands[name] |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
330 | except: |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
331 | return None |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
332 | |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
333 | # |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | # make_regex |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
335 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
336 | # Takes the argument list and returns a corresponding regular expression |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | # |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
338 | def make_regex (arglist): |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
339 | if arglist == None: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
340 | return '^.+$' |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
341 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | gotoptional = False |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | gotvariadic = False |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
344 | regex = '' |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
345 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
346 | for arg in arglist.split (' '): |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
347 | if gotvariadic: |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
348 | raise CommandError ('''variadic argument is not last''') |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
349 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | if arg == '': |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
351 | continue |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
352 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
65
diff
changeset
|
353 | gotliteral = False |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
354 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
355 | if arg[0] == '[' and arg[-1] == ']': |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
356 | arg = arg[1:-1] |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
357 | gotoptional = True |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
358 | elif arg[0] == '<' and arg[-1] == '>': |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
359 | if gotoptional: |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
360 | raise CommandError ('''mandatory argument after optional one''') |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
361 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
362 | arg = arg[1:-1] |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
363 | else: |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
65
diff
changeset
|
364 | gotliteral = True |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
365 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
366 | if arg[-3:] == '...': |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
367 | gotvariadic = True |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
124
diff
changeset
|
368 | arg = arg[:-3] |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
369 | |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | if gotoptional == False: |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
371 | regex += r'\s+' |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
372 | else: |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
373 | regex += r'\s*' |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
374 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
65
diff
changeset
|
375 | if gotliteral: |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
65
diff
changeset
|
376 | regex += arg |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
65
diff
changeset
|
377 | elif gotoptional: |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
378 | if gotvariadic: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
379 | regex += r'(.*)' |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
380 | else: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
381 | regex += r'([^ ]*)' |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
382 | else: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
383 | if gotvariadic: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
384 | regex += r'(.+)' |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
385 | else: |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
386 | regex += r'([^ ]+)' |
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
387 | |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
388 | if not gotvariadic: |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
389 | regex += r'\s*' |
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
390 | |
62
052a8a1e3d7d
- revamped commands, added a much more modular system. not everything migrated yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
391 | return '^[^ ]+%s$' % regex |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
392 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
393 | def irc_command (**command): |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
394 | def result (fn): |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
395 | command['name'] = fn.__name__ |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
396 | command['description'] = fn.__doc__ |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
397 | command['function'] = fn |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
398 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
399 | if command['description'] == None: |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
400 | command['description'] = '' |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
401 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
402 | if 'level' not in command: |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
403 | command['level'] = 'normal' |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
404 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
405 | if 'args' not in command: |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
406 | command['args'] = None |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
407 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
408 | install_command (command, sys.modules[fn.__module__]) |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
409 | return fn |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
149
diff
changeset
|
410 | return result |