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:
123
diff
changeset
|
1 | ''' |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
2 | Copyright 2014-2015 Teemu Piippo |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
3 | All rights reserved. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
4 | |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
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:
123
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
7 | are met: |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
8 | |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
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:
123
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
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:
123
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:
123
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
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:
123
diff
changeset
|
15 | derived from this software without specific prior written permission. |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
16 | |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
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:
123
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:
123
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:
123
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:
123
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
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:
123
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:
123
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:
123
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:
123
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:
123
diff
changeset
|
27 | ''' |
7b2cd8b1ba86
- now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
123
diff
changeset
|
28 | |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
128
diff
changeset
|
29 | from __future__ import print_function |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | import math |
76 | 31 | import json |
105 | 32 | import re |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
33 | import modulecore |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
34 | import utility |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
35 | import calc |
153
497b7290977d
More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents:
152
diff
changeset
|
36 | import urllib.parse |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
38 | @modulecore.irc_command (args='<value> as <valuetype>') |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
39 | def convert (bot, args, reply, error, **rest): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
40 | '''Performs numeric conversion.''' |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
41 | try: |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
42 | value = float (args['value']) |
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
43 | except Exception as e: |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
44 | error (str (e)) |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
45 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | valuetype = args['valuetype'] |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | if valuetype in ['radians', 'degrees']: |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | if valuetype == 'radians': |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | radvalue = value |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | degvalue = (value * 180.) / math.pi |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | else: |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | radvalue = (value * math.pi) / 180. |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | degvalue = value |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
56 | reply ('%s radians, %s degrees (%s)' % (radvalue, degvalue, degvalue % 360.)) |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | return |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | if valuetype in ['celsius', 'fahrenheit']: |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | if valuetype == 'celsius': |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | celvalue = value |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | fahrvalue = value * 1.8 + 32 |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | else: |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | celvalue = (value - 32) / 1.8 |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | fahrvalue = value |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
67 | reply ('%s degrees celsius, %s degrees fahrenheit' % (celvalue, fahrvalue)) |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | return |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
70 | error ('unknown valuetype %s, expected one of: degrees, radians (angle conversion), ' + |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | 'celsius, fahrenheit (temperature conversion)' % valuetype) |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
73 | @modulecore.irc_command (args='<term...>') |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
74 | def ud (bot, args, reply, error, **rest): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
75 | '''Looks up a term in urban dictionary.''' |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | try: |
76 | 77 | url = 'http://api.urbandictionary.com/v0/define?term=%s' % (args['term'].replace (' ', '%20')) |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
128
diff
changeset
|
78 | response = utility.read_url (url) |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | data = json.loads (response) |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | if not 'list' in data \ |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | or len(data['list']) == 0 \ |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | or not 'word' in data['list'][0] \ |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | or not 'definition' in data['list'][0]: |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
85 | error ("couldn't find a definition of \002%s\002" % args['term']) |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | word = data['list'][0]['word'] |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | definition = data['list'][0]['definition'].replace ('\r', ' ').replace ('\n', ' ').replace (' ', ' ') |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | up = data['list'][0]['thumbs_up'] |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | down = data['list'][0]['thumbs_down'] |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
91 | reply ("\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down)) |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | except Exception as e: |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
93 | error ('Urban dictionary lookup failed: %s' % e) |
102
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
94 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
95 | @modulecore.irc_command() |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
96 | def commands (bot, reply, ident, host, **rest): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
97 | '''Lists commands available to the calling user.''' |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
98 | commandlist = modulecore.get_available_commands (ident, host) |
102
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
99 | partitioned=[] |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
100 | |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
101 | while len (commandlist) > 0: |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
102 | partitioned.append (commandlist[0:15]) |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
103 | commandlist = commandlist[15:] |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
104 | |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
105 | for part in partitioned: |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
106 | reply ('\002Available commands\002: %s' % (", ".join (part))) |
102
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
107 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
108 | @modulecore.irc_command (args='<command>') |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
109 | def help (bot, reply, ident, host, args, error, **rest): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
110 | '''Prints help about a given command.''' |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
111 | cmd = modulecore.get_command_by_name (args['command']) |
102
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
112 | |
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
113 | if not cmd: |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
114 | error ('unknown command \'%s\'' % args['command']) |
102
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
115 | |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
116 | if not modulecore.is_available (cmd, ident, host): |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
117 | error ('you may not use %s' % cmd['name']) |
102
2bad379cd416
- added .help and .commands
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
118 | |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
119 | reply ('%s %s: %s' % (cmd['name'], cmd['args'], cmd['description'])) |
105 | 120 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
121 | @modulecore.irc_command() |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
122 | def calcfunctions (bot, reply, **rest): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
123 | '''Lists the functions supported by .calc.''' |
123
aeb0d0788869
- added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents:
121
diff
changeset
|
124 | reply ('Available functions for .calc: %s' % \ |
146
c17b82b1f573
Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents:
128
diff
changeset
|
125 | ', '.join (sorted ([name for name, data in calc.Functions.items()]))) |
105 | 126 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
127 | @modulecore.irc_command (args='<expression...>') |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
128 | def calc (bot, reply, args, **rest): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
129 | '''Calculates a mathematical expression.''' |
128
bd949c554dd2
Major refactor: moved calculator routines into a Calculator class.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
124
diff
changeset
|
130 | reply (calc.Calculator().calc (args['expression'])) |
113
08e9b1c1b324
- added page system to prevent commands from printing too much output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
111
diff
changeset
|
131 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
132 | @modulecore.irc_command() |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
133 | def more (commandObject, **rest): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
134 | '''Prints subsequent command result pages.''' |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
135 | modulecore.print_responses (commandObject) |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
113
diff
changeset
|
136 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
137 | @modulecore.irc_command() |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
138 | def yes (**k): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
139 | '''Confirms the previous command.''' |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
140 | modulecore.confirm (k, True) |
117
6c0609395889
- added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents:
113
diff
changeset
|
141 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
142 | @modulecore.irc_command() |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
143 | def no (**k): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
144 | '''Unconfirms the previous command.''' |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
145 | modulecore.confirm (k, False) |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
146 | |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
147 | @modulecore.irc_command (args='<link...>') |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
148 | def bitly (reply, args, **k): |
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
149 | '''Shortens a link using bit.ly.''' |
121
ac07779f788d
- reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
150 | reply ('Result: %s' % utility.shorten_link (args['link'])) |
148 | 151 | |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
152 | @modulecore.irc_command (args='<command...>') |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
153 | def py (reply, args, **rest): |
155
5a9b5065f53f
Remove more manifests
Teemu Piippo <crimsondusk64@gmail.com>
parents:
154
diff
changeset
|
154 | '''Evaluates the given Python string using appspot.com.''' |
153
497b7290977d
More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents:
152
diff
changeset
|
155 | url = 'http://eval.appspot.com/eval?statement=' + urllib.parse.quote (args['command']) |
154
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
156 | result = utility.read_url (url, timeout=15).splitlines() |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
157 | |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
158 | if not result: |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
159 | reply ('No output.') |
df862cca1773
Added ability to define an IRC command with a function decorator instead of a manifest entry
Teemu Piippo <crimsondusk64@gmail.com>
parents:
153
diff
changeset
|
160 | return |
148 | 161 | |
162 | # \x0f is the 'reset colors' code, prepended to all reply lines to prevent other bots from | |
163 | # reacting to this .py call. | |
164 | if result[0] == 'Traceback (most recent call last):': | |
165 | reply ('\x0f' + result[-1]) | |
166 | else: | |
167 | for line in result: | |
168 | reply ('\x0f' + line) |