Subversion Repositories navi

Rev

Rev 270 | Rev 284 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
214 szabot 1
#! /usr/bin/env python
247 muzer 2
#    This file is part of Tsim Apiak.
214 szabot 3
#
247 muzer 4
#    Tsim Apiak is free software: you can redistribute it and/or modify
5
#    it under the terms of the GNU General Public Licence as published by
6
#    the Free Software Foundation, either version 3 of the Licence, or
7
#    (at your option) any later version.
214 szabot 8
#
247 muzer 9
#    In addition to this, you must also comply with clause 4 of the
10
#    Apache Licence, version 2.0, concerning attribution. Where there
11
#    is a contradiction between the two licences, the GPL
12
#    takes preference.
13
#
14
#    Tsim Apiak is distributed in the hope that it will be useful,
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
#    GNU General Public License for more details.
18
#
19
#    You should have received a copy of the GNU General Public License
20
#    along with Tsim Apiak.  If not, see <http://www.gnu.org/licenses/>.#
214 szabot 21
 
278 muzer 22
from irc.bot import SingleServerIRCBot
23
from irc.client import nm_to_n
214 szabot 24
from tsimapiak import translate
278 muzer 25
from threading import *
214 szabot 26
 
27
class Bot(SingleServerIRCBot):
28
    def __init__(self, channel, nickname, server, port=6667):
29
        SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
30
        self.channel = channel
31
 
278 muzer 32
    def pingit(self, c):
33
        c.ping("testing")
34
        t = Timer(30, self.pingit, [c])
35
        t.start()
36
 
214 szabot 37
    def on_nicknameinuse(self, c, e):
38
        c.nick(c.get_nickname() + "_")
39
 
40
    def on_welcome(self, c, e):
41
        c.join(self.channel)
42
        c.privmsg("NiceBot", "asztallab")
278 muzer 43
        t = Timer(30, self.pingit, [c])
44
        t.start()
214 szabot 45
 
46
    def on_privmsg(self, c, e):
246 szabot 47
        self.do_command(e, e.arguments()[0], True)
214 szabot 48
 
49
    def on_pubmsg(self, c, e):
50
        a = e.arguments()[0]
51
        if a[0] == "!":
246 szabot 52
            self.do_command(e, a[1:].strip(), False)
214 szabot 53
        return
54
 
55
    def do_command(self, e, cmd, priv):
278 muzer 56
#        try:
57
#            cmd = cmd.decode("utf-8")
58
#        except:
59
#            cmd = cmd.decode("iso-8859-1")
214 szabot 60
        if priv:
61
            nick = nm_to_n(e.source())
62
        else:
63
            nick = self.channel
64
        c = self.connection
65
 
66
        if (cmd.split(" ")[0] == "tr") or (cmd.split(" ")[0] == "translate"):
67
            lang = "eng"
238 muzer 68
            if len(cmd.split(" ")) > 1 and cmd.split(" ")[1].startswith("-"):
270 muzer 69
                if cmd.split(" ")[1][1:] in ("hu", "de", "ptbr", "est", "sv", "nl"):
214 szabot 70
                    lang = cmd.split(" ")[1][1:]
71
                sent = " ".join(cmd.split(" ")[2:])
72
            else:
73
                sent = " ".join(cmd.split(" ")[1:])
74
            translated = []
75
            for word in translate.translatesent(sent, lang):
76
                translated.append(word["translated"])
77
            translated = nm_to_n(e.source()) + ": " + " | ".join(translated)
278 muzer 78
            c.privmsg(nick, translated)
214 szabot 79
 
80
def main():
81
    #bot = Bot("#tim32", "TsimApiak", "irc.tim32.org", 6667)
278 muzer 82
    bot = Bot("#na'vi", "TsimApiak", "ikranakel.learnnavi.org", 6667)
214 szabot 83
    bot.start()
84
 
85
if __name__ == "__main__":
86
    main()