#! /usr/bin/env python # -*- coding: UTF-8 -*- """ Botux: bot in python creato da Frafra (francesco.it@gmail.com) con l'aiuto di C8E e di bornFreeThinker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ # Descrizione del file __module_name__ = "BoTux" __module_version__ = __revision__ = versione = "0.5.7" __module_description__ = "Bot programmato in Python" # Importazione dei moduli necessari import re, socket, time, wx#, encodings.idna, encodings.ascii from httplib import HTTPConnection from urllib import quote print old = time.time() class BoTuxFrame(wx.Frame): """Parte grafica""" def __init__(self): """ __init__ """ app = wx.GetApp() # Frame wx.Frame.__init__(self, None, wx.NewId(), "BoTux - Versione " + versione, size = (500, 298), style = wx.CAPTION) # Menu' menu_file = wx.Menu() menu_bar = wx.MenuBar() menu_bar.Append(menu_file, "&File"); # Voce "Informazioni" myid = wx.NewId() menu_file.Append(myid, "&Informazioni", "Qualche informazione sul programma") wx.EVT_MENU(self, myid, self.oninfo) # Voce "Ringraziamenti" myid = wx.NewId() menu_file.Append(myid, "&Ringraziamenti", "Ringraziamenti ai programmatori") wx.EVT_MENU(self, myid, self.onthanks) # Separatore menu_file.AppendSeparator() # Voce "Esci" myid = wx.NewId() menu_file.Append(myid, "&Esci", "Esci dal programma") wx.EVT_MENU(self, myid, self.onesci) # Creazione barra di stato self.SetMenuBar(menu_bar) self.CreateStatusBar() # Pannello self.panel = wx.Panel(self, wx.NewId()) # Box n.1 self.box = wx.StaticBox(self.panel, wx.NewId(), "Comandi", pos = (1, 0), size = (245, 60)) # Bottone n.1 myid = wx.NewId() self.button = wx.Button(self.panel, myid, "Avvia", pos = (11, 20)) wx.EVT_BUTTON(self, myid, self.onstart) # Box n.2 self.box = wx.StaticBox(self.panel, wx.NewId(), "Impostazioni", pos = (1, 60), size = (245, 177)) # Testo n.1 wx.StaticText(self.panel, -1, "Proprietario:", wx.Point(11, 87)) # User myid = wx.NewId() wx.TextCtrl(self.panel, myid, "User", wx.Point(100, 84), size = (135, 24)) wx.EVT_TEXT(self, myid, self.onroot) # Testo n.2 wx.StaticText(self.panel, -1, "Passsword del nick:", wx.Point(11, 117)) # Password myid = wx.NewId() wx.TextCtrl(self.panel, myid, app.passwd, wx.Point(155, 114), size = (80, 24)) wx.EVT_TEXT(self, myid, self.onpasswd) # Testo n.3 wx.StaticText(self.panel, -1, "Server:", wx.Point(11, 147)) # Server myid = wx.NewId() wx.TextCtrl(self.panel, myid, app.server, wx.Point(70, 144), size = (165, 24)) wx.EVT_TEXT(self, myid, self.onsrv) # Testo n.4 wx.StaticText(self.panel, -1, "Canali:", wx.Point(11, 177)) # Canali myid = wx.NewId() wx.TextCtrl(self.panel, myid, str(app.chan[0]), wx.Point(70, 174), size = (165, 24)) wx.EVT_TEXT(self, myid, self.onchan) # Testo n.5 wx.StaticText(self.panel, -1, "Porta:", wx.Point(11, 207)) # Porta myid = wx.NewId() wx.TextCtrl(self.panel, myid, str(app.port), wx.Point(70, 204), size = (100, 24)) wx.EVT_TEXT(self, myid, self.onport) # Box n.3 self.box = wx.StaticBox(self.panel, wx.NewId(), "Informazioni", pos = (254, 0), size = (244, 237)) # Testo n.6 wx.StaticText(self.panel, -1, "MSN:", wx.Point(265, 26)) # MSN myid = wx.NewId() wx.TextCtrl(self.panel, myid, app.info["!msn"], wx.Point(325, 23), size = (162, 24)) wx.EVT_TEXT(self, myid, self.onmsn) # Testo n.7 wx.StaticText(self.panel, -1, "Yahoo:", wx.Point(265, 56)) # YahooIM myid = wx.NewId() wx.TextCtrl(self.panel, myid, app.info["!yahoo"], wx.Point(325, 53), size = (162, 24)) wx.EVT_TEXT(self, myid, self.onyahoo) # Testo n.8 wx.StaticText(self.panel, -1, "ICQ:", wx.Point(265, 86)) # ICQ myid = wx.NewId() wx.TextCtrl(self.panel, myid, app.info["!icq"], wx.Point(325, 83), size = (162, 24)) wx.EVT_TEXT(self, myid, self.onicq) # Testo n.9 wx.StaticText(self.panel, -1, "AIM:", wx.Point(265, 116)) # AIM myid = wx.NewId() wx.TextCtrl(self.panel, myid, app.info["!aim"], wx.Point(325, 113), size = (162, 24)) wx.EVT_TEXT(self, myid, self.onaim) # Testo n.10 wx.StaticText(self.panel, -1, "Jabber:", wx.Point(265, 146)) # Jabber myid = wx.NewId() wx.TextCtrl(self.panel, myid, app.info["!jabber"], wx.Point(325, 143), size = (162, 24)) wx.EVT_TEXT(self, myid, self.onjabber) # Testo n.11 wx.StaticText(self.panel, -1, "Mail:", wx.Point(265, 196)) # Mail myid = wx.NewId() wx.TextCtrl(self.panel, myid, app.info["!mail"], wx.Point(325, 193), size = (162, 24)) wx.EVT_TEXT(self, myid, self.onmail) # Azioni per i menu' e per i settaggi def oninfo(self, dummy): """Per le info""" wx.MessageBox("Versione %s di BoTux" % versione, "Informazioni", wx.OK | wx.ICON_INFORMATION) def onthanks(self, dummy): """Per i ringraziamenti""" wx.MessageBox( "Creato da Frafra con l'aiuto di C8E e di bornFreeThinker.", "Ringraziamenti", wx.OK | wx.ICON_INFORMATION) def onesci(self, dummy): """Per uscire""" print self.Close(1) def onstart(self, dummy): """Per avviare""" app = wx.GetApp() if app.init(app.passwd, app.server, app.port) == 0: wx.MessageBox("Inizializzazione fallita.", "Errore", wx.OK | wx.ICON_ERROR) else: while app.avvio(app.info): time.sleep(.1) # Azioni per le informazioni personali def onroot(self, event): """Prende la variabile root""" app = wx.GetApp() app.root = event.GetString() def onpasswd(self, event): """Prende la variabile passwd""" app = wx.GetApp() app.passwd = event.GetString() def onsrv(self, event): """Prende la variabile server""" app = wx.GetApp() app.server = event.GetString() def onchan(self, event): """Prende la variabile chan""" app = wx.GetApp() if "," in event.GetString(): app.chan = event.GetString().split(",") else: app.chan = [event.GetString()] def onport(self, event): """Prende la variabile port""" app = wx.GetApp() app.port = event.GetString() def onmsn(self, event): """Prende la variabile msn""" app = wx.GetApp() app.info["!msn"] = event.GetString() def onyahoo(self, event): """Prende la variabile yahoo""" app = wx.GetApp() app.info["!yahoo"] = event.GetString() def onicq(self, event): """Prende la variabile icq""" app = wx.GetApp() app.info["!icq"] = event.GetString() def onaim(self, event): """Prende la variabile aim""" app = wx.GetApp() app.info["!aim"] = event.GetString() def onjabber(self, event): """Prende la variabile jabber""" app = wx.GetApp() app.info["!jabber"] = event.GetString() def onmail(self, event): """Prende la variabile mail""" app = wx.GetApp() app.info["!mail"] = event.GetString() class BoTux(wx.App): """Creazione della classe "BoTux" """ def invia(self, rcvr, txt): """ Funzione d'invio """ self.IRC.send("PRIVMSG %s :%s\n" % (rcvr, txt)) print "I've sent:", txt def init(self, passwd, server, port): """Inizializzazione""" try: # Connessione al server self.IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.IRC.connect((server, int(port))) # Login self.IRC.send("USER %s %s %s %s\n" % ((self.me,)*4)) self.IRC.send("NICK %s\n" % self.me) if passwd != "": self.IRC.send("NS IDENTIFY %s\n" % passwd) # Accesso al/ai canali i = 0 for i in self.chan: self.IRC.send("JOIN %s\n" % str(i)) return 1 except StandardError: return 0 def privmsg(self, msg, info): """Funzione per "privmsg" """ self.nick, msg[3] = (msg[0])[1:].split("!", 1)[0], msg[3][1:] if msg[2] == self.me: rcvr = self.nick else: rcvr = msg[2] # Funzione per salutare if " ".join(msg[3:]).lower() == "ciao " + self.me.lower(): self.invia(rcvr, "Ciao %s." % self.nick) # Funzione per visualizzare le informazioni elif msg[3] in self.info.keys(): txt = msg[3][1:].capitalize() if info[msg[3]] != "": self.invia(rcvr, "%s: %s." % (txt, info[msg[3]])) else: self.invia(rcvr, "Informazione non disponibile.") elif msg[3] in self.cmd: self.cmd[msg[3]](msg, rcvr) elif msg[3] in self.supercmd.keys() and self.nick == self.root: if self.supercmd[msg[3]](msg) == None: return 1 else: return 0 elif msg[3].lower() == "s" and self.p[0] == 1: # Funzione per ricevere la risposta al rejoin self.IRC.send("JOIN %s\n" % self.p[1]) time.sleep(2) self.invia(self.p[1], "Non kickkarmi, %s." % self.p[2]) self.chan.append(self.p[1]) self.p[0] = 0 return 1 def cerca(self, msg, rcvr): """ Funzione per la ricerca su google """ if len(msg)>4: site = HTTPConnection("www.google.com") txt2 = quote(" ".join(msg[4:])) if "|" == msg[4][0]: lang = msg[4][1:] txt = "&meta=lr%%3Dlang_" + lang + "&hl=" + lang site.request("GET", "/search?q=%s%s" % (txt2, txt)) else: txt = "&meta=lr%%3Dlang_en&hl=en" site.request("GET", "/search?q=%s%s" % (txt2, txt)) tipo = ".+?
.+?)>(?P