Dave Cridland Application 2012

From XMPP WIKI
Revision as of 15:14, 11 January 2012 by Dwd (talk | contribs) (Created page with "= Dave Cridland's Application, 2012 = When voting reopens, please run the following to assist in your voting. <pre> #!/usr/bin/env python # -*- coding: utf-8 -*- import sys im...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Dave Cridland's Application, 2012

When voting reopens, please run the following to assist in your voting.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import sleekxmpp
# Use a modern Sleek - then you're using my SASL implementation.
# (Massively improved by Lance Stout).
import logging

# Python versions before 3.0 do not use UTF-8 encoding
# by default. To ensure that Unicode is handled properly
# throughout SleekXMPP, we will set the default encoding
# ourselves to UTF-8.
if sys.version_info < (3, 0):
    reload(sys)
    sys.setdefaultencoding('utf8')
else:
    raw_input = input

MEMBERBOT = 'memberbot@jabber.org'

class VotingAid(sleekxmpp.ClientXMPP):
    def __init__(self, jid, password):
        sleekxmpp.ClientXMPP.__init__(self, jid, password)
        self.add_event_handler("session_start", self.start)
        self.add_event_handler("message", self.message)

    def message(self, msg):
        if msg['from'].bare == MEMBERBOT:
            if 'Dave Cridland' in msg['body']:
                # I'd mention here about my work on the XSF Board, my previous work on the Council,
                # the work on IETF directorates, the RFCs, the XEPs.
                # I could talk about working for Isode, directly on XMPP servers used by government and military.
                # But let me make this simpler for you:
                self.sendMessage(msg['from'], 'yes', mtype='chat')
            elif 'type ok to begin' in msg['body']:
                # This one says yes or no. But expects ok...
                self.sendMessage(msg['from'], 'ok', mtype='chat')
            elif 'Would you like to vote on the current topic' in msg['body']:
                # Special case this so we don't need to ask the user.
                self.sendMessage(msg['from'], 'yes', mtype='chat')
            elif 'yes or no' in msg['body']:
                print msg['body']
                self.sendMessage(msg['from'], raw_input('Yes or no? '), mtype='chat')
            else:
                import sys
                sys.exit() # Rough, but we're done.

    def start(self, evt):
        self.get_roster()
        self.send_presence(ppriority=-1, pstatus='VotingAid')
        self.sendMessage(MEMBERBOT, "Hello!", mtype='chat')

def main():
    import getpass
    # Setup logging.
    logging.basicConfig(level=logging.DEBUG,
                        format='%(levelname)-8s %(message)s')
    tmp = VotingAid(raw_input('Jid: '), getpass.getpass('Password: '))
    tmp.connect()
    while True:
        tmp.process(block=True)

if __name__ == '__main__':
    main()