mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 19:19:55 +00:00
Update examples to work with Python3 (raw_input vs input)
This commit is contained in:
parent
8d998d71a3
commit
015f662249
10 changed files with 49 additions and 10 deletions
|
@ -24,6 +24,8 @@ import sleekxmpp
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class CommandBot(sleekxmpp.ClientXMPP):
|
class CommandBot(sleekxmpp.ClientXMPP):
|
||||||
|
@ -79,9 +81,21 @@ class CommandBot(sleekxmpp.ClientXMPP):
|
||||||
here to persist across handler callbacks.
|
here to persist across handler callbacks.
|
||||||
"""
|
"""
|
||||||
form = self['xep_0004'].makeForm('form', 'Greeting')
|
form = self['xep_0004'].makeForm('form', 'Greeting')
|
||||||
|
form['instructions'] = 'Send a custom greeting to a JID'
|
||||||
form.addField(var='greeting',
|
form.addField(var='greeting',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
label='Your greeting')
|
label='Your greeting')
|
||||||
|
form.addField(var='recipient',
|
||||||
|
ftype='jid-single',
|
||||||
|
label='Who to greet')
|
||||||
|
form.addField(var='message',
|
||||||
|
ftype='text-multi',
|
||||||
|
label='Your message')
|
||||||
|
form.addField(var='demobool',
|
||||||
|
ftype='boolean',
|
||||||
|
label='Test booleans',
|
||||||
|
desc='Test default values too',
|
||||||
|
value=True)
|
||||||
|
|
||||||
session['payload'] = form
|
session['payload'] = form
|
||||||
session['next'] = self._handle_command_complete
|
session['next'] = self._handle_command_complete
|
||||||
|
@ -123,8 +137,14 @@ class CommandBot(sleekxmpp.ClientXMPP):
|
||||||
form = payload
|
form = payload
|
||||||
|
|
||||||
greeting = form['values']['greeting']
|
greeting = form['values']['greeting']
|
||||||
self.send_message(mto=session['from'],
|
recipient = form['values']['recipient']
|
||||||
mbody="%s, World!" % greeting)
|
message = '\n'.join(form['values']['message'])
|
||||||
|
|
||||||
|
if recipient is None:
|
||||||
|
recipient = session['from']
|
||||||
|
self.send_message(mto=recipient,
|
||||||
|
mbody="%s, %s!\n%s" % (greeting, recipient, message),
|
||||||
|
mtype='chat')
|
||||||
|
|
||||||
# Having no return statement is the same as unsetting the 'payload'
|
# Having no return statement is the same as unsetting the 'payload'
|
||||||
# and 'next' session values and returning the session.
|
# and 'next' session values and returning the session.
|
||||||
|
@ -176,6 +196,7 @@ if __name__ == '__main__':
|
||||||
xmpp.register_plugin('xep_0030') # Service Discovery
|
xmpp.register_plugin('xep_0030') # Service Discovery
|
||||||
xmpp.register_plugin('xep_0004') # Data Forms
|
xmpp.register_plugin('xep_0004') # Data Forms
|
||||||
xmpp.register_plugin('xep_0050') # Adhoc Commands
|
xmpp.register_plugin('xep_0050') # Adhoc Commands
|
||||||
|
xmpp.register_plugin('xep_0199', {'keepalive': True, 'frequency':15})
|
||||||
|
|
||||||
# If you are working with an OpenFire server, you may need
|
# If you are working with an OpenFire server, you may need
|
||||||
# to adjust the SSL version used:
|
# to adjust the SSL version used:
|
||||||
|
|
|
@ -24,6 +24,8 @@ import sleekxmpp
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class CommandUserBot(sleekxmpp.ClientXMPP):
|
class CommandUserBot(sleekxmpp.ClientXMPP):
|
||||||
|
|
|
@ -27,6 +27,8 @@ from sleekxmpp.xmlstream.stanzabase import ET, registerStanzaPlugin
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class Config(ElementBase):
|
class Config(ElementBase):
|
||||||
|
|
|
@ -25,6 +25,8 @@ import sleekxmpp
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class Disco(sleekxmpp.ClientXMPP):
|
class Disco(sleekxmpp.ClientXMPP):
|
||||||
|
|
|
@ -24,6 +24,8 @@ import sleekxmpp
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class EchoBot(sleekxmpp.ClientXMPP):
|
class EchoBot(sleekxmpp.ClientXMPP):
|
||||||
|
@ -34,7 +36,7 @@ class EchoBot(sleekxmpp.ClientXMPP):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, jid, password):
|
def __init__(self, jid, password):
|
||||||
sleekxmpp.ClientXMPP.__init__(self, jid, password)
|
sleekxmpp.ClientXMPP.__init__(self, jid, password, plugin_config={'feature_mechanisms': {'use_mech': 'PLAIN'}})
|
||||||
|
|
||||||
# The session_start event will be triggered when
|
# The session_start event will be triggered when
|
||||||
# the bot establishes its connection with the server
|
# the bot establishes its connection with the server
|
||||||
|
|
|
@ -23,6 +23,8 @@ import sleekxmpp
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class MUCBot(sleekxmpp.ClientXMPP):
|
class MUCBot(sleekxmpp.ClientXMPP):
|
||||||
|
|
|
@ -24,6 +24,8 @@ import sleekxmpp
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class PingTest(sleekxmpp.ClientXMPP):
|
class PingTest(sleekxmpp.ClientXMPP):
|
||||||
|
|
|
@ -24,6 +24,8 @@ import sleekxmpp
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class EchoBot(sleekxmpp.ClientXMPP):
|
class EchoBot(sleekxmpp.ClientXMPP):
|
||||||
|
|
|
@ -27,6 +27,8 @@ from sleekxmpp.exceptions import IqError, IqTimeout
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class RosterBrowser(sleekxmpp.ClientXMPP):
|
class RosterBrowser(sleekxmpp.ClientXMPP):
|
||||||
|
|
|
@ -24,6 +24,8 @@ import sleekxmpp
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
else:
|
||||||
|
raw_input = input
|
||||||
|
|
||||||
|
|
||||||
class SendMsgBot(sleekxmpp.ClientXMPP):
|
class SendMsgBot(sleekxmpp.ClientXMPP):
|
||||||
|
|
Loading…
Reference in a new issue