docs/ikteam: Delete most files.
[haiku.git] / 3rdparty / mmu_man / irc / Haiku / plugin.py
blob1bdb6cb2767b5b8d398ed723c86bc736923eb867
1 # -*- coding: utf-8 -*-
2 ###
3 # Copyright (c) 2012, François Revol
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions, and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright notice,
12 # this list of conditions, and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the author of this software nor the name of
15 # contributors to this software may be used to endorse or promote products
16 # derived from this software without specific prior written consent.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29 ###
31 import supybot.conf as conf
32 import supybot.utils as utils
33 from supybot.commands import *
34 import supybot.callbacks as callbacks
35 import supybot.log as log
37 import random
39 import errors
41 class Haiku(callbacks.Plugin):
42 def __init__(self, irc):
43 #log.error("plop")
44 #print "plop"
45 self.fortunes = []
46 fortunes = open("/home/revol/devel/haiku/trunk/data/system/data/fortunes/Haiku", "r")
47 print fortunes
48 if fortunes:
49 fortune = ""
50 for line in fortunes:
51 if line == "%\n":
52 self.fortunes.append(fortune)
53 fortune = ""
54 else:
55 fortune += line
56 fortunes.close()
58 self.__parent = super(Haiku, self)
59 self.__parent.__init__(irc)
61 def error(self, irc, msg, args):
62 """<error>
64 Returns the code and value for the given <error> value or code.
65 """
66 print "Haiku: error"
67 print args
68 if not args:
69 raise callbacks.ArgumentError
70 for arg in args:
71 err = None
72 if arg in errors.errors:
73 err = errors.errors[arg]
74 key = arg
75 else:
76 try:
77 i = int(arg, 0)
78 except ValueError:
79 irc.errorInvalid('argument', arg, Raise=True)
80 for e in errors.errors:
81 if errors.errors[e]['value'] == i:
82 err = errors.errors[e]
83 key = e
84 if err is None:
85 irc.reply("Unknown error '%s'" % (arg))
86 else:
87 expr = err['expr']
88 value = err['value']
89 r = "%s = %s = 0x%x (%d): %s" % (key, expr, int(value), value, err['str'])
90 irc.reply(r)
92 def haiku(self, irc, msg, args):
93 """
95 Returns a random haiku.
96 """
98 if len(self.fortunes) > 0:
99 h = self.fortunes[int(random.random() * len(self.fortunes))].split('\n')
100 for l in h:
101 if l != "":
102 irc.reply(l, prefixNick = False)
103 else:
104 irc.reply("No haiku found")
106 def reportbugs(self, irc, msg, args):
109 Returns some infos on reporting bugs.
112 to = None
113 if len(args) > 0:
114 to = args[0]
115 t = "If you think there is a bug in Haiku, please report a bug so we can remember to fix it. cf. http://dev.haiku-os.org/wiki/ReportingBugs"
116 irc.reply(t, to = to)
118 def patchwanted(self, irc, msg, args):
121 Returns some infos on submitting patches.
124 to = None
125 if len(args) > 0:
126 to = args[0]
127 t = "Haiku is Free Software, therefore you can fix it yourself and send a patch, which would likely be very appreciated. cf. http://dev.haiku-os.org/wiki/SubmittingPatches"
128 irc.reply(t, to = to)
130 def download(self, irc, msg, args):
133 Returns download links.
136 to = None
137 if len(args) > 0:
138 to = args[0]
139 t = "Current release: http://www.haiku-os.org/get-haiku - Nightly builds: http://haiku-files.org/haiku/development/"
140 irc.reply(t, to = to)
142 def dl(self, irc, msg, args):
145 Returns download links.
147 return self.download(irc, msg, args)
149 def vi(self, irc, msg, args):
152 Trolls.
155 to = None
156 if len(args) > 0:
157 to = args[0]
158 t = "emacs!"
159 irc.reply(t, to = to)
161 def emacs(self, irc, msg, args):
164 Trolls.
167 to = None
168 if len(args) > 0:
169 to = args[0]
170 t = "vi!"
171 irc.reply(t, to = to)
173 def bored(self, irc, msg, args):
176 Returns some infos.
179 to = None
180 if len(args) > 0:
181 to = args[0]
182 t = "Why won't you get on some easy tasks then? http://dev.haiku-os.org/wiki/EasyTasks"
183 irc.reply(t, to = to)
185 def jlg(self, irc, msg, args):
188 Praise Jean-Louis Gassée.
191 to = None
192 if len(args) > 0:
193 to = args[0]
194 t = "Jean-Louis Gassée, such a Grand Fromage!"
195 irc.reply(t, to = to)
197 def basement(self, irc, msg, args):
200 Puts people to work.
203 to = "everyone"
204 who = "them"
205 if len(args) > 0:
206 to = args[0]
207 who = "him"
208 if len(args) > 1:
209 to = ' and '.join([', '.join(args[:-1]), args[-1]])
210 who = "them"
211 t = "sends %s to BGA's basement and chains %s to a post in front of a computer. Get to work!" % (to, who)
212 irc.reply(t, action = True)
214 def trout(self, irc, msg, args):
217 Puts someone back to his place.
220 if len(args) > 0:
221 to = args[0]
222 if len(args) > 1:
223 to = ' and '.join([', '.join(args[:-1]), args[-1]])
224 t = "slaps %s with a trout." % (to)
225 irc.reply(t, action = True)
227 def plop(self, irc, msg, args):
230 Returns some infos.
233 to = None
234 if len(args) > 0:
235 to = args[0]
236 t = "plop"
237 irc.reply(t, to = to)
239 def shibboleet(self, irc, msg, args):
242 Tech support.
245 irc.reply("http://xkcd.com/806/ Tech Support")
247 Class = Haiku
249 # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: