X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sid%2Fecho.py;h=96ea393d93c90180128f971c097d5fbea22bbbb0;hb=HEAD;hp=f0e05b8e9d35cfedd93ff3fc72c0233b4447b28d;hpb=c42c7531be1c512846ab8795f331e676ab53f003;p=sid.git diff --git a/sid/echo.py b/sid/echo.py index f0e05b8..12b4376 100644 --- a/sid/echo.py +++ b/sid/echo.py @@ -1,23 +1,14 @@ # -*- coding: utf-8 -*- - -# Copyright (C) 2007-2012 Thomas Perl -# Copyright (C) 2014 kaliko - -# 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 -# the Free Software Foundation, version 3 only. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# SPDX-FileCopyrightText: 2007-2012 Thomas Perl +# SPDX-FileCopyrightText: 2014, 2020 kaliko +# SPDX-License-Identifier: GPL-3.0-or-later from .plugin import Plugin, botcmd + class Echo(Plugin): + """Drops a message to be sent when someone gets online. + """ def __init__(self, bot): Plugin.__init__(self, bot) @@ -28,10 +19,12 @@ class Echo(Plugin): # any presences you send yourself. To limit event handling # to a single room, use the events muc::room@server::presence, # muc::room@server::got_online, or muc::room@server::got_offline. - bot.add_event_handler("muc::%s::presence" % self.bot.room, self.log_presence) + bot.add_event_handler("muc::%s::presence" % + self.bot.room, self.log_presence) def log_presence(self, pres): - self.log.debug('{0}: {1}'.format(pres['muc']['nick'], pres['type'])) + """Handler method registering MUC participants presence""" + self.log.debug('%s: %s', pres['muc']['nick'], pres['type']) nick = pres['muc']['nick'] self.presence.update({nick: (pres['muc']['role'], pres['type'])}) self.log.debug(self.presence) @@ -40,13 +33,14 @@ class Echo(Plugin): self.send(self.bot.room, self.inbox.get(nick).pop(), mtype='groupchat') - self.inbox.pop(nick) + self.inbox.pop(nick) @botcmd def tell(self, message, args): - """drop a message to be sent when someone gets online. - !tell queue : messages in queue - !tell : append to in queue""" + """Drops a message to be sent when someone gets online. + + * ``!tell queue`` : messages in queue + * ``!tell ``: append to in queue""" if not len(args): msg = 'Missing arguments:\n{}'.format(self.tell.__doc__) self.reply(message, msg) @@ -54,13 +48,13 @@ class Echo(Plugin): if len(args) == 1: if args[0] == 'queue': msg = '\n'.join(['{0}:\n\t{1}'.format(k, '\n'.join(v)) - for k, v in self.inbox.items()]) + for k, v in self.inbox.items()]) self.reply(message, msg) return if args[0] == 'purge': sender = message['from'].resource if self.presence[sender][0] == 'moderator': - self.online = set() + self.inbox = dict() return if len(args) < 2: msg = 'Please provide a message:\n{}'.format(self.tell.__doc__) @@ -69,18 +63,19 @@ class Echo(Plugin): self._handle_msg(message) def _handle_msg(self, message): + """Format and drop message in the inbox""" sender = message['from'].resource recipient = message['body'].split()[1] tell_msg = ' '.join(message['body'].split()[2:]) - self.log.debug('{0}: {1}'.format(recipient, tell_msg)) + self.log.debug('%s: %s', recipient, tell_msg) letter = '{0}, {1} wanted you to know: {2}'.format(recipient, sender, tell_msg) if (self.presence.get(recipient) and self.presence[recipient][1] == 'available'): return if recipient in self.inbox.keys(): - self.inbox[recipient].append(letter) + self.inbox[recipient].append(letter) else: - self.inbox[recipient] = [letter] + self.inbox[recipient] = [letter] # VIM MODLINE