1# -*- coding: utf-8 -*-
2###
3# Copyright (c) 2012, Fran��ois Revol
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#
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.
17#
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###
30
31import supybot.conf as conf
32import supybot.utils as utils
33from supybot.commands import *
34import supybot.callbacks as callbacks
35import supybot.log as log
36
37import random
38
39import errors
40
41class 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()
57
58        self.__parent = super(Haiku, self)
59        self.__parent.__init__(irc)
60
61    def error(self, irc, msg, args):
62        """<error>
63
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)
91
92    def haiku(self, irc, msg, args):
93        """
94
95        Returns a random haiku.
96        """
97
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")
105
106    def reportbugs(self, irc, msg, args):
107        """
108
109        Returns some infos on reporting bugs.
110        """
111
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)
117
118    def patchwanted(self, irc, msg, args):
119        """
120
121        Returns some infos on submitting patches.
122        """
123
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)
129
130    def download(self, irc, msg, args):
131        """
132
133        Returns download links.
134        """
135
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)
141
142    def dl(self, irc, msg, args):
143        """
144
145        Returns download links.
146        """
147        return self.download(irc, msg, args)
148
149    def vi(self, irc, msg, args):
150        """
151
152        Trolls.
153        """
154
155        to = None
156        if len(args) > 0:
157            to = args[0]
158        t = "emacs!"
159        irc.reply(t, to = to)
160
161    def emacs(self, irc, msg, args):
162        """
163
164        Trolls.
165        """
166
167        to = None
168        if len(args) > 0:
169            to = args[0]
170        t = "vi!"
171        irc.reply(t, to = to)
172
173    def bored(self, irc, msg, args):
174        """
175
176        Returns some infos.
177        """
178
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)
184
185    def jlg(self, irc, msg, args):
186        """
187
188        Praise Jean-Louis Gass��e.
189        """
190
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)
196
197    def basement(self, irc, msg, args):
198        """
199
200        Puts people to work.
201        """
202
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)
213
214    def trout(self, irc, msg, args):
215        """
216
217        Puts someone back to his place.
218        """
219
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)
226
227    def plop(self, irc, msg, args):
228        """
229
230        Returns some infos.
231        """
232
233        to = None
234        if len(args) > 0:
235            to = args[0]
236        t = "plop"
237        irc.reply(t, to = to)
238
239    def shibboleet(self, irc, msg, args):
240        """
241
242        Tech support.
243        """
244
245        irc.reply("http://xkcd.com/806/ Tech Support")
246
247Class = Haiku
248
249# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
250