def start(self, gmail_account, password): jid=xmpp.JID(gmail_account) user, server, password = jid.getNode(), jid.getDomain(), password self.conn=xmpp.Client(server, debug=self.debug) #talk.google.com print strings().connecting_string%(self.server_host,self.server_port) if(configs().prod==1): conres=self.conn.connect( server=(self.server_host, self.server_port)) else: conres=self.conn.connect( server=(self.server_host, self.server_port),secure=0 ) if not conres: print strings().cannot_connect%server sys.exit(1) if conres<>'tls': print strings().not_secure_connection print user,password authres=self.conn.auth(user, password) if not authres: print strings().wrong_password sys.exit(1) if authres<>"sasl": print strings().no_sasl%server self.conn.RegisterHandler("message", self.controller) self.conn.RegisterHandler('presence',self.presenceHandler) self.conn.sendInitPresence() self.setState(self.show, self.status) print strings().bot_start self.GoOn()
def presenceHandler(self, conn, presence): #print_info(presence) if(configs().prod==0): # so that it can load if any changes are there reload(all_handlers) if presence: if presence.getType()=='subscribe': #auto add friends.. Keep some checking here, and LOG! jid = presence.getFrom().getStripped() self.authorize(jid) self.replyMessage(jid, strings().first_welcome_msg%jid) else: all_handlers.presence().handle(conn, presence)
def controller(self, conn, message): text = message.getBody() user = message.getFrom() # try: if text: text = text.encode('utf-8', 'ignore') if(configs().prod==0): # so that it can load if any changes are there reload(all_handlers) reply, status, availability = all_handlers.im().handle(conn, text, user) if(reply is not None): self.replyMessage(user, reply) if((status is not None ) and (availability is not None)): self.setState( availability, status)
def handle(self, conn, text, user): plugins_list = [ os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname(__file__) + "/plugins/commander_*.py") ] # print (plugins) for i in plugins_list: try: class_name = getattr(plugins, i, i) if configs().prod == 0: reload(class_name) reply, status, availability = class_name.commander().try_text(text, user) return reply, status, availability except: pass return None
# the Free Software Foundation; either version 3 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. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # PyGtalkRobot Homepage: http://code.google.com/p/pygtalkrobot/ # RaspiBot Homepage: http://code.google.com/p/pygtalkrobot/ # import time # import RPi.GPIO as GPIO from PyGtalkRobot import GtalkRobot from configs.config import configs from configs.strings import strings # GPIO.setmode(GPIO.BOARD) # or GPIO.setmode(GPIO.BCM) ############################################################################################################################ if __name__ == "__main__": bot = GtalkRobot(configs().settings["server"], configs().settings["port"], debug=configs().debug) bot.setState("available", strings().status) bot.start(configs().settings["BOT_GTALK_USER"], configs().settings["BOT_GTALK_PASS"])