26:a24aee2294c6
Anton Shestakov <av6@dwimlabs.net>, 2016-07-18
rollbot: move logging below the lookups, split the line Helps keeping options and their defaults closer.

next change 27:a5f866114e79
previous change 25:2dd502d4e9df

rollbot.py

Permissions: -rw-r--r--

Other formats: Feeds:
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
#!/usr/bin/env python
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
import cgi
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
import logging
11
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
import random
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
import re
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
import sys
5
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
from argparse import ArgumentParser, FileType, SUPPRESS
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
5
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
import yaml
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
import sleekxmpp
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
if sys.version_info < (3, 0):
14
14:2fffb6701d37 rollbot: use sleekxmpp.util.misc_ops.setdefaultencoding()
Anton Shestakov <av6@dwimlabs.net>
previous changes: 13:d4079b5ce7a0
line | diff
from sleekxmpp.util.misc_ops import setdefaultencoding
14:2fffb6701d37 rollbot: use sleekxmpp.util.misc_ops.setdefaultencoding()
Anton Shestakov <av6@dwimlabs.net>
previous changes: 13:d4079b5ce7a0
line | diff
setdefaultencoding('utf8')
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
def simple_markup(string):
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
plain = ''
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
html = ''
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
tagre = re.compile(r'\{(\w+)\}(.*?)\{/\1\}')
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
plain = tagre.sub(r'\2', string)
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
def get_replacement(match):
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
code = match.group(1)
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
text = match.group(2)
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
codes = {
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
'B': 'color: blue;',
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
'G': 'color: green;',
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
'i': 'font-style: italic;',
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
't': 'font-family: monospace;'
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
}
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
style = codes.get(code, '')
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
return '<span style="{}">{}</span>'.format(style, text)
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
html = tagre.sub(get_replacement, cgi.escape(string))
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
return plain, html
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
10
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
class Command(object):
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
name = 'command'
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
def __init__(self, rollbot):
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
self.rollbot = rollbot
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
def usage(self):
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
return '(no help available, try experimenting)'
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
11
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
class Roll(Command):
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
name = 'roll'
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
regex = re.compile('^(?P<times>\d+)?d(?P<sides>\d+)$', re.IGNORECASE)
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
def usage(self):
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
return (
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
'{t}%s <X>D<Y>{/t} to roll {t}Y{/t}-sided die {t}X{/t} times,'
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
' if {t}X{/t} is 1 it can be omitted' % self.name)
11
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
def respond(self, words, message):
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
if len(words) == 2:
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
match = self.regex.match(words[1])
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
if match is not None:
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
times = match.group('times')
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
if times is None:
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
times = 1
19
19:fade59cdf584 rollbot: transform times and sides to integers early
Anton Shestakov <av6@dwimlabs.net>
previous changes: 18:7cf8ac0d3ebc
line | diff
else:
19:fade59cdf584 rollbot: transform times and sides to integers early
Anton Shestakov <av6@dwimlabs.net>
previous changes: 18:7cf8ac0d3ebc
line | diff
times = int(times)
19:fade59cdf584 rollbot: transform times and sides to integers early
Anton Shestakov <av6@dwimlabs.net>
previous changes: 18:7cf8ac0d3ebc
line | diff
sides = int(match.group('sides'))
18
18:7cf8ac0d3ebc rollbot: only roll things with at least 2 sides and do it at least once
Anton Shestakov <av6@dwimlabs.net>
previous changes: 17:20b47f01a71d
line | diff
if times > 0 and sides > 1:
19
19:fade59cdf584 rollbot: transform times and sides to integers early
Anton Shestakov <av6@dwimlabs.net>
previous changes: 18:7cf8ac0d3ebc
line | diff
rolls, total = self.roll(times, sides)
18
18:7cf8ac0d3ebc rollbot: only roll things with at least 2 sides and do it at least once
Anton Shestakov <av6@dwimlabs.net>
previous changes: 17:20b47f01a71d
line | diff
return self.format(rolls, total)
11
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
return '%s usage: %s' % (self.name, self.usage())
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
def roll(self, times, sides):
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
results = [random.randint(1, sides) for i in range(times)]
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
total = sum(results)
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
return results, total
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
def format(self, rolls, total):
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
if len(rolls) == 1:
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
return '{G}%d{/G}' % total
11
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
else:
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
sequence = ' + '.join('{B}%d{/B}' % r for r in rolls)
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
return '(%s) = {G}%d{/G}' % (sequence, total)
11
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
17
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
class Flip(Command):
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
name = 'flip'
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
def usage(self):
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
return '{t}%s{/t} {i}or{/i} {t}%s <1st-option>[ or] <2nd-option>{/t}' % (self.name, self.name)
17
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
def respond(self, words, message):
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
if len(words) == 1:
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
option = self.flip(('heads', 'tails'))
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
elif len(words) == 3:
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
option = self.flip(words[1:])
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
elif len(words) == 4 and words[2].lower() == 'or':
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
option = self.flip((words[1], words[3]))
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
else:
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
return '%s usage: %s' % (self.name, self.usage())
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
return self.format(option)
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
def flip(self, options):
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
return random.choice(options)
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
def format(self, option):
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
return '{G}%s{/G}' % option
17
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
10
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
class Help(Command):
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
name = 'help'
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
def usage(self):
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
return '{t}%s{/t} {i}or{/i} {t}%s <command>{/t}' % (self.name, self.name)
10
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
def respond(self, words, message):
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
if len(words) == 2:
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
cmdname = words[1]
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
if cmdname in self.rollbot.commands:
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
command = self.rollbot.commands[cmdname]
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
return '%s usage: %s' % (command.name, command.usage())
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
else:
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
return 'no such command: %s' % cmdname
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
elif len(words) == 1:
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
cmds = ' '.join(sorted(self.rollbot.commands.keys()))
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
return 'available commands: %s' % cmds
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
else:
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
return '%s usage: %s' % (self.name, self.usage())
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
class RollBot(sleekxmpp.ClientXMPP):
7
7:7b7c6ad5c7ba rollbot: configurable command prefix
Anton Shestakov <av6@dwimlabs.net>
previous changes: 6:bddc9023ac66
line | diff
def __init__(self, jid, password, nick, prefix):
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
sleekxmpp.ClientXMPP.__init__(self, jid, password)
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
2
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
self.nick = nick
7
7:7b7c6ad5c7ba rollbot: configurable command prefix
Anton Shestakov <av6@dwimlabs.net>
previous changes: 6:bddc9023ac66
line | diff
self.prefix = prefix
10
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
self.commands = {}
11
11:1be0d90ed46b rollbot: finally, roll command (basic <X>D<Y>)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 10:9fa8b4b32368
line | diff
self.add_command(Roll)
17
17:20b47f01a71d rollbot: flip command for flipping a coin
Anton Shestakov <av6@dwimlabs.net>
previous changes: 16:767c4ae49fc0
line | diff
self.add_command(Flip)
10
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
self.add_command(Help)
2
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
self.add_event_handler('session_start', self.start)
6
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
self.add_event_handler('message', self.message)
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
self.add_event_handler('groupchat_message', self.muc_message)
2
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
self.add_event_handler('groupchat_invite', self.muc_invite)
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
self.add_event_handler('groupchat_direct_invite', self.muc_direct_invite)
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
10
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
def add_command(self, commandcls):
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
self.commands[commandcls.name] = commandcls(self)
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
def start(self, event):
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
self.get_roster()
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
self.send_presence()
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
6
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
def message(self, msg):
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
if msg['type'] not in ('chat', 'normal'):
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
return
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
9
9:88927ae72d71 rollbot: allow prefix in direct chat, don't strip tabs
Anton Shestakov <av6@dwimlabs.net>
previous changes: 8:8645840c53d1
line | diff
mbody = msg['body'].lstrip()
9:88927ae72d71 rollbot: allow prefix in direct chat, don't strip tabs
Anton Shestakov <av6@dwimlabs.net>
previous changes: 8:8645840c53d1
line | diff
if mbody.startswith(self.prefix):
9:88927ae72d71 rollbot: allow prefix in direct chat, don't strip tabs
Anton Shestakov <av6@dwimlabs.net>
previous changes: 8:8645840c53d1
line | diff
mbody = mbody[len(self.prefix):]
9:88927ae72d71 rollbot: allow prefix in direct chat, don't strip tabs
Anton Shestakov <av6@dwimlabs.net>
previous changes: 8:8645840c53d1
line | diff
9:88927ae72d71 rollbot: allow prefix in direct chat, don't strip tabs
Anton Shestakov <av6@dwimlabs.net>
previous changes: 8:8645840c53d1
line | diff
mbody = mbody.lstrip(' ')
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
rbody, rxbody = self.respond(mbody)
6
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
if rbody:
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
msg.reply(rbody)
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
msg['html']['body'] = rxbody
6
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
msg.send()
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
def muc_message(self, msg):
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
if msg['mucnick'] == self.nick:
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
return
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
mbody = msg['body'].lstrip()
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
if mbody.startswith(self.nick):
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
mbody = mbody[len(self.nick):]
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
elif mbody.startswith(self.prefix):
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
mbody = mbody[len(self.prefix):]
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
else:
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
return
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
9
9:88927ae72d71 rollbot: allow prefix in direct chat, don't strip tabs
Anton Shestakov <av6@dwimlabs.net>
previous changes: 8:8645840c53d1
line | diff
mbody = mbody.lstrip(':, ')
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
rbody, rxbody = self.respond(mbody)
6
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
if rbody:
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
rbody = '%s: %s' % (msg['mucnick'], rbody)
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
rxbody = '%s: %s' % (cgi.escape(msg['mucnick']), rxbody)
6
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
msg.reply(rbody)
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
msg['html']['body'] = rxbody
6
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
msg.send()
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
2
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
def muc_invite(self, invite):
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
room = invite['from']
15
15:26b97ecf8e16 rollbot: extract password from XEP-0045 mediated invitation by hand
Anton Shestakov <av6@dwimlabs.net>
previous changes: 14:2fffb6701d37
line | diff
# https://github.com/fritzy/SleekXMPP/issues/409
15:26b97ecf8e16 rollbot: extract password from XEP-0045 mediated invitation by hand
Anton Shestakov <av6@dwimlabs.net>
previous changes: 14:2fffb6701d37
line | diff
ns = 'http://jabber.org/protocol/muc#user'
15:26b97ecf8e16 rollbot: extract password from XEP-0045 mediated invitation by hand
Anton Shestakov <av6@dwimlabs.net>
previous changes: 14:2fffb6701d37
line | diff
pel = invite.find('{%(ns)s}x/{%(ns)s}password' % {'ns': ns})
15:26b97ecf8e16 rollbot: extract password from XEP-0045 mediated invitation by hand
Anton Shestakov <av6@dwimlabs.net>
previous changes: 14:2fffb6701d37
line | diff
password = pel.text if pel is not None else ''
2
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
self.plugin['xep_0045'].joinMUC(room, self.nick, password=password, wait=True)
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
def muc_direct_invite(self, invite):
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
room = invite['groupchat_invite']['jid']
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
password = invite['groupchat_invite']['password']
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
self.plugin['xep_0045'].joinMUC(room, self.nick, password=password, wait=True)
2:11e99d62ba12 rollbot: join rooms when invited
Anton Shestakov <av6@dwimlabs.net>
previous changes: 1:e7b3233bb582
line | diff
6
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
def respond(self, message, prefix=None):
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
plain = ''
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
html = ''
10
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
words = message.split()
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
if words:
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
cmdname = words[0].lower()
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
if cmdname in self.commands:
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
command = self.commands[cmdname]
10:9fa8b4b32368 rollbot: help command that can list available commands and explain their usage
Anton Shestakov <av6@dwimlabs.net>
previous changes: 9:88927ae72d71
line | diff
response = command.respond(words, message)
21
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
plain, html = simple_markup(response)
21:4470846e7c0c rollbot: simple markup for coloring/styling messages
Anton Shestakov <av6@dwimlabs.net>
previous changes: 20:8bd991e9b7ff
line | diff
return plain, html
6
6:bddc9023ac66 rollbot: try and respond to various commands (none yet) when addressed
Anton Shestakov <av6@dwimlabs.net>
previous changes: 5:754ae6ae2c54
line | diff
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
5
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
def lookup(key, args, config, default=None):
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
if hasattr(args, key):
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
return getattr(args, key)
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
return config.get(key, default)
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
5
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
def main():
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
parser = ArgumentParser(argument_default=SUPPRESS)
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
parser.add_argument('-c', '--config', help='configuration file (YAML)', type=FileType('r'))
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
25
25:2dd502d4e9df rollbot: split a long line
Anton Shestakov <av6@dwimlabs.net>
previous changes: 24:9c7f41fa62d1
line | diff
group = parser.add_argument_group(
25:2dd502d4e9df rollbot: split a long line
Anton Shestakov <av6@dwimlabs.net>
previous changes: 24:9c7f41fa62d1
line | diff
'main configuration',
25:2dd502d4e9df rollbot: split a long line
Anton Shestakov <av6@dwimlabs.net>
previous changes: 24:9c7f41fa62d1
line | diff
'options that can also be specified in the configuration file')
5
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
group.add_argument('-j', '--jid', help='JID to use')
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
group.add_argument('-p', '--password', help='password to use')
8
8:8645840c53d1 rollbot: add the default value of --nick option to its help string
Anton Shestakov <av6@dwimlabs.net>
previous changes: 7:7b7c6ad5c7ba
line | diff
group.add_argument('-n', '--nick', help='MUC nickname (default: rollbot)')
7
7:7b7c6ad5c7ba rollbot: configurable command prefix
Anton Shestakov <av6@dwimlabs.net>
previous changes: 6:bddc9023ac66
line | diff
group.add_argument('--prefix', help='command prefix (default: !)')
3
3:12c6cbab21e4 rollbot: add --quiet in addition to --debug
Anton Shestakov <av6@dwimlabs.net>
previous changes: 2:11e99d62ba12
line | diff
3:12c6cbab21e4 rollbot: add --quiet in addition to --debug
Anton Shestakov <av6@dwimlabs.net>
previous changes: 2:11e99d62ba12
line | diff
group = parser.add_mutually_exclusive_group()
20
20:8bd991e9b7ff rollbot: shorten lines of log verbosity arguments creation
Anton Shestakov <av6@dwimlabs.net>
previous changes: 19:fade59cdf584
line | diff
extra = dict(action='store_const', dest='loglevel', default=logging.INFO)
20:8bd991e9b7ff rollbot: shorten lines of log verbosity arguments creation
Anton Shestakov <av6@dwimlabs.net>
previous changes: 19:fade59cdf584
line | diff
group.add_argument('-q', '--quiet', help='set logging to ERROR', const=logging.ERROR, **extra)
20:8bd991e9b7ff rollbot: shorten lines of log verbosity arguments creation
Anton Shestakov <av6@dwimlabs.net>
previous changes: 19:fade59cdf584
line | diff
group.add_argument('-d', '--debug', help='set logging to DEBUG', const=logging.DEBUG, **extra)
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
args = parser.parse_args()
24
24:9c7f41fa62d1 rollbot: inline "if hasattr(args, 'config')" block
Anton Shestakov <av6@dwimlabs.net>
previous changes: 23:48c2c7e345ca
line | diff
config = yaml.safe_load(args.config) if hasattr(args, 'config') else {}
5
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
jid = lookup('jid', args, config)
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
password = lookup('password', args, config)
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
nick = lookup('nick', args, config, default='rollbot')
7
7:7b7c6ad5c7ba rollbot: configurable command prefix
Anton Shestakov <av6@dwimlabs.net>
previous changes: 6:bddc9023ac66
line | diff
prefix = lookup('prefix', args, config, default='!')
5
5:754ae6ae2c54 rollbot: ability to specify a config file (YAML) with jid, password and nick
Anton Shestakov <av6@dwimlabs.net>
previous changes: 4:4b0145336c46
line | diff
26
26:a24aee2294c6 rollbot: move logging below the lookups, split the line
Anton Shestakov <av6@dwimlabs.net>
previous changes: 25:2dd502d4e9df
line | diff
logging.basicConfig(
26:a24aee2294c6 rollbot: move logging below the lookups, split the line
Anton Shestakov <av6@dwimlabs.net>
previous changes: 25:2dd502d4e9df
line | diff
level=args.loglevel,
26:a24aee2294c6 rollbot: move logging below the lookups, split the line
Anton Shestakov <av6@dwimlabs.net>
previous changes: 25:2dd502d4e9df
line | diff
format='%(asctime)s %(levelname)-8s %(message)s')
26:a24aee2294c6 rollbot: move logging below the lookups, split the line
Anton Shestakov <av6@dwimlabs.net>
previous changes: 25:2dd502d4e9df
line | diff
7
7:7b7c6ad5c7ba rollbot: configurable command prefix
Anton Shestakov <av6@dwimlabs.net>
previous changes: 6:bddc9023ac66
line | diff
rollbot = RollBot(jid, password, nick, prefix)
1
1:e7b3233bb582 rollbot: be nice and auto authorize contacts, then subscribe back to them
Anton Shestakov <av6@dwimlabs.net>
previous changes: 0:ce9855302692
line | diff
rollbot.auto_authorize = True
1:e7b3233bb582 rollbot: be nice and auto authorize contacts, then subscribe back to them
Anton Shestakov <av6@dwimlabs.net>
previous changes: 0:ce9855302692
line | diff
rollbot.auto_subscribe = True
23
23:48c2c7e345ca rollbot: two spaces before inline comments (flake8)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 21:4470846e7c0c
line | diff
rollbot.register_plugin('xep_0030') # Service Discovery
23:48c2c7e345ca rollbot: two spaces before inline comments (flake8)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 21:4470846e7c0c
line | diff
rollbot.register_plugin('xep_0045') # Multi-User Chat
23:48c2c7e345ca rollbot: two spaces before inline comments (flake8)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 21:4470846e7c0c
line | diff
rollbot.register_plugin('xep_0092') # Software Version
23:48c2c7e345ca rollbot: two spaces before inline comments (flake8)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 21:4470846e7c0c
line | diff
rollbot.register_plugin('xep_0199') # XMPP Ping
23:48c2c7e345ca rollbot: two spaces before inline comments (flake8)
Anton Shestakov <av6@dwimlabs.net>
previous changes: 21:4470846e7c0c
line | diff
rollbot.register_plugin('xep_0249') # Direct MUC Invitations
0
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
if rollbot.connect():
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
logging.info('RollBot connected')
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
rollbot.process(block=True)
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
logging.info('RollBot disconnected')
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
else:
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
logging.fatal("RollBot couldn't connect")
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
if __name__ == '__main__':
0:ce9855302692 rollbot: connect and send presence
Anton Shestakov <av6@dwimlabs.net>
previous changes:
line | diff
main()