def _command(message, arguments, state): match = re.fullmatch( r'^(.+) (in|on|at) (.+) with "(.+)"', arguments ) if match: if not state.subscriptions: state.subscriptions = Heap() who = match.group(1) if who == 'me': who = message.origin preposition = match.group(2) when = match.group(3) try: if preposition == 'in': when = when.split(':') when = datetime.now() + timedelta(hours=int(when[0]), minutes=int(when[1])) elif preposition == 'on': when = datetime.strptime('%Y-%m-%d', when) elif preposition == 'at': now = datetime.now() when = when.split(':') now.hour = int(when[0]) now.minute = int(when[0]) when = now except Exception as e: logger.exception(e) yield Message.privmsg(message.recipient, message.origin + ': Come again?') return what = match.group(4) state.subscriptions.push((when, who, preposition, what)) yield Message.privmsg(message.recipient, message.origin + ': You betcha')
def run(message, state): if message.text.endswith('++'): thing = message.text.rstrip('+') if thing in state: modattr(state, thing, succ) else: setattr(state, thing, 1) response = 'The value of {} is now {}'.format(thing, getattr(state, thing)) yield Message.privmsg(message.recipient, response)
def handle(message, settings, state): try: to, text = split_text(message.text) except TypeError: pass else: if to == state.nick and text == 'hello': yield Message.privmsg(message.recipient, 'hello to you too, {}!'.format(message.origin)) yield from run_plugins(message, settings.behaviour.command_prefix, settings.plugins, state.plugins)
def run(message, state): if state.subscriptions: try: when, who, preposition, what = state.subscriptions.pop() except IndexError: logger.debug("Didn't remind anybody") return else: if when <= datetime.now(): yield Message.privmsg(message.recipient, '{}: Reminder: {}'.format(who, what)) else: state.subscriptions.push((when, who, preposition, what)) else: logger.debug("Didn't remind anybody")
def run(message, state): last_message = state.last_message.get(message.origin) log.debug('Last message from %s: %s', message.origin, last_message) if last_message: subst_re = re.compile(r'^s/(.+)/(.+)/(\w)?$') match = subst_re.match(message.text) if match: del state['last_message'][message.origin] corrected = re.sub(match.group(1), match.group(2), last_message) log.debug('Corrected message: %s', corrected) yield Message.privmsg( message.recipient, 'Corrected message: <{}> {}'.format(message.origin, corrected) ) else: log.debug('New last message for %s: %s', message.origin, message.text) state.last_message[message.origin] = message.text
def run(message, arguments, state): if 'called' in state: yield Message.privmsg(message.recipient, 'You have already tested') else: state.called = True yield Message.privmsg(message.recipient, 'Testing first time!')