From 5c86e6a6743662d5b2b23cba0d35272c2448b860 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 11 Mar 2009 16:54:14 +0530 Subject: Auto authentication of new contacts by Sarath Lakshman --- bots/eng-mal-bot.py | 90 +++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 51 deletions(-) (limited to 'bots/eng-mal-bot.py') diff --git a/bots/eng-mal-bot.py b/bots/eng-mal-bot.py index cc11209..36e7fe0 100755 --- a/bots/eng-mal-bot.py +++ b/bots/eng-mal-bot.py @@ -1,11 +1,12 @@ -#!/usr/bin/python #!/usr/bin/env python # -*- coding: utf-8 -*- # # eng-mal-bot.py A Jabbe buddy bot which provide eng-mal dictionary lookup service # -# Copyright (c) 2009 Santhosh Thottingal -# http://smc.org.in/ +# Copyright (c) 2009 +# Santhosh Thottingal +# Sarath Lakshman +# Swathanthra Malayalam Computing(http://smc.org.in/) # # 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 @@ -19,54 +20,13 @@ import xmpp from xmpp.protocol import * -from xmpp.roster import * import os options = { 'JID': 'eng.mal.dict@gmail.com', - 'Password': 'രഹസ്യം(പറയൂല!) !', + 'Password': 'mail santhosh if you need password for this', } -def presenceHandler(conn,presence_node): - """ Handler for playing a sound when particular contact became online """ - targetJID='node@domain.org' - print presence_node.getFrom() - if presence_node.getFrom().bareMatch(targetJID): - # play a sound - pass -def iqHandler(conn,iq_node): - """ Handler for processing some "get" query from custom namespace""" - reply=iq_node.buildReply('result') - # ... put some content into reply node - conn.send(reply) - raise NodeProcessed # This stanza is fully processed - - -def messageHandler(conn,message): - user = message.getFrom() - text = message.getBody() - if(text): - if " " in text: - command, args = text.split(" ", 1) - else: - command, text = text, "" - command = command.upper() - #ഇതു വര്‍ക്കു ചെയ്യുന്നില്ല! :( - if command == "SUBSCRIBE": - rost=Roster().PlugIn(conn) - rost=Roster.getRoster() - ros.Authorize(user) - reply = "Authorized." - conn.send(reply) - raise NodeProcessed # This stanza is fully processed - else: - command = "dict --database dict-en-ml '" + message.getBody() +"'" - stdin, stdout = os.popen2(command) - # ... put some content into reply node - conn.send( xmpp.Message( user,stdout.read())) - stdout.close() - raise NodeProcessed # This stanza is fully processed - class ConnectionError: pass class AuthorizationError: pass class NotImplemented: pass @@ -79,9 +39,9 @@ class Bot: # connect... jid = xmpp.JID(JID) - self.connection = xmpp.Client(jid.getDomain(), debug=['always', 'browser', 'testcommand']) + self.connection = xmpp.Client(jid.getDomain(), debug=[]) result = self.connection.connect() - + if result is None: raise ConnectionError @@ -91,13 +51,12 @@ class Bot: if result is None: raise AuthorizationError - self.connection.RegisterHandler('presence',presenceHandler) - self.connection.RegisterHandler('iq',iqHandler) - self.connection.RegisterHandler('message',messageHandler) + self.connection.RegisterHandler('presence',self.presenceHandler) + self.connection.RegisterHandler('message',self.messageHandler) # ...become available self.connection.sendInitPresence() # presence - self.connection.sendInitPresence(requestRoster=0) + #self.connection.sendInitPresence(requestRoster=0) def loop(self): """ Do nothing except handling new xmpp stanzas. """ @@ -106,7 +65,36 @@ class Bot: pass except KeyboardInterrupt: pass + + def messageHandler(self, conn,mess_node): + + if(mess_node.getBody()): + command = "dict --database dict-en-ml '" + mess_node.getBody() +"'" + stdin, stdout = os.popen2(command) + # ... put some content into reply node + conn.send( xmpp.Message( mess_node.getFrom() ,stdout.read())) + stdout.close() + raise NodeProcessed # This stanza is fully processed + + + + def presenceHandler(self, conn, presence): + + '''Auto authorizing chat invites''' + if presence: + if presence.getType()=='subscribe': + jid = presence.getFrom().getStripped() + self.connection.getRoster().Authorize(jid) + + targetJID='node@domain.org' + print presence.getFrom() + if presence.getFrom().bareMatch(targetJID): + # play a sound + pass + + bot = Bot(**options) bot.loop() + -- cgit From 2cea4faae67f7ec777bd781b0f77bac0abc527a9 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Fri, 13 Mar 2009 16:44:38 +0530 Subject: Fix for displaying no definition found by Ragsagar --- bots/eng-mal-bot.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'bots/eng-mal-bot.py') diff --git a/bots/eng-mal-bot.py b/bots/eng-mal-bot.py index 36e7fe0..f6a5644 100755 --- a/bots/eng-mal-bot.py +++ b/bots/eng-mal-bot.py @@ -21,10 +21,11 @@ import xmpp from xmpp.protocol import * import os +import commands options = { 'JID': 'eng.mal.dict@gmail.com', - 'Password': 'mail santhosh if you need password for this', + 'Password': '*******', } class ConnectionError: pass @@ -70,10 +71,13 @@ class Bot: if(mess_node.getBody()): command = "dict --database dict-en-ml '" + mess_node.getBody() +"'" - stdin, stdout = os.popen2(command) - # ... put some content into reply node - conn.send( xmpp.Message( mess_node.getFrom() ,stdout.read())) - stdout.close() + output = commands.getoutput(command) + if output.find('No definitions found') is not -1: + print "No definitions found" + conn.send( xmpp.Message( mess_node.getFrom(),'No Definitions Found')) + else : + print "definition found" + conn.send( xmpp.Message( mess_node.getFrom() ,output)) raise NodeProcessed # This stanza is fully processed -- cgit From 7102af081488fbc7aa021cbd5008bed07b864e33 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Thu, 23 Apr 2009 11:48:38 +0530 Subject: Adding Ragsagar's name in contributors --- bots/eng-mal-bot.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bots/eng-mal-bot.py') diff --git a/bots/eng-mal-bot.py b/bots/eng-mal-bot.py index f6a5644..3b3ffac 100755 --- a/bots/eng-mal-bot.py +++ b/bots/eng-mal-bot.py @@ -6,6 +6,7 @@ # Copyright (c) 2009 # Santhosh Thottingal # Sarath Lakshman +# Ragsagar # Swathanthra Malayalam Computing(http://smc.org.in/) # # This program is free software; you can redistribute it and/or modify -- cgit From ee0f42962618bb4d3b607cc18248957c72f18961 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Tue, 12 May 2009 20:36:02 +0530 Subject: Removed the dependency on command line access of dictd daemon by using python dictd library --- bots/eng-mal-bot.py | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'bots/eng-mal-bot.py') diff --git a/bots/eng-mal-bot.py b/bots/eng-mal-bot.py index 3b3ffac..844fe29 100755 --- a/bots/eng-mal-bot.py +++ b/bots/eng-mal-bot.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# eng-mal-bot.py A Jabbe buddy bot which provide eng-mal dictionary lookup service +# eng-mal-bot.py A Jabber buddy bot which provide eng-mal dictionary lookup service # # Copyright (c) 2009 # Santhosh Thottingal @@ -23,10 +23,11 @@ import xmpp from xmpp.protocol import * import os import commands +from dictdlib import DictDB options = { 'JID': 'eng.mal.dict@gmail.com', - 'Password': '*******', + 'Password': 'eng.mal.', #This is fake password. } class ConnectionError: pass @@ -68,37 +69,35 @@ class Bot: except KeyboardInterrupt: pass - def messageHandler(self, conn,mess_node): - - if(mess_node.getBody()): - command = "dict --database dict-en-ml '" + mess_node.getBody() +"'" - output = commands.getoutput(command) - if output.find('No definitions found') is not -1: - print "No definitions found" - conn.send( xmpp.Message( mess_node.getFrom(),'No Definitions Found')) - else : - print "definition found" - conn.send( xmpp.Message( mess_node.getFrom() ,output)) + def messageHandler(self, conn,message_node): + word = message_node.getBody() + if word : + output = self.getdef(word) + conn.send( xmpp.Message( message_node.getFrom() ,output)) raise NodeProcessed # This stanza is fully processed - - + def getdef(self, word): + en_ml_db = None + try: + #search the dictionary in same directory of program + en_ml_db = DictDB("freedict-eng-mal") + except: + #retry in standard directory of dictd + en_ml_db = DictDB("/usr/share/dictd/freedict-eng-mal") + if en_ml_db == None: + return "[FATAL ERROR] Dictionary not found." + try: + return en_ml_db.getdef(word)[0] + except: + return "No definitions found" + def presenceHandler(self, conn, presence): - '''Auto authorizing chat invites''' if presence: - if presence.getType()=='subscribe': - jid = presence.getFrom().getStripped() - self.connection.getRoster().Authorize(jid) + if presence.getType() == 'subscribe': + jabber_id = presence.getFrom().getStripped() + self.connection.getRoster().Authorize(jabber_id) - targetJID='node@domain.org' - print presence.getFrom() - if presence.getFrom().bareMatch(targetJID): - # play a sound - pass - - - bot = Bot(**options) bot.loop() -- cgit