2013-04-13 20:33:06 +00:00
|
|
|
"""
|
|
|
|
This plugin adds a :term:`/pacokick` command, which is a random kick.
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
|
|
|
|
/pacokick
|
|
|
|
|
|
|
|
Run the command in a room where you are a moderator to
|
|
|
|
kick someone randomly.
|
|
|
|
"""
|
|
|
|
|
2011-11-09 02:07:51 +00:00
|
|
|
from random import choice
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.tabs import MucTab
|
2011-11-09 02:07:51 +00:00
|
|
|
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.plugin import BasePlugin
|
2011-11-09 02:07:51 +00:00
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
2011-11-09 02:07:51 +00:00
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
2018-08-15 11:13:17 +00:00
|
|
|
self.api.add_command(
|
|
|
|
'pacokick',
|
|
|
|
self.command_kick,
|
|
|
|
usage='',
|
|
|
|
help='Kick a random user.',
|
|
|
|
short='Kick a random user')
|
2011-11-09 02:07:51 +00:00
|
|
|
|
|
|
|
def command_kick(self, arg):
|
2013-03-08 21:53:35 +00:00
|
|
|
tab = self.api.current_tab()
|
2011-11-09 02:07:51 +00:00
|
|
|
if isinstance(tab, MucTab):
|
2018-08-15 11:13:17 +00:00
|
|
|
kickable = list(
|
|
|
|
filter(lambda x: x.affiliation in ('none', 'member'),
|
|
|
|
tab.users))
|
2011-11-09 02:07:51 +00:00
|
|
|
if kickable:
|
|
|
|
to_kick = choice(kickable)
|
|
|
|
if to_kick:
|
|
|
|
to_kick = to_kick.nick
|
2018-08-15 11:13:17 +00:00
|
|
|
tab.command_kick(to_kick + ' ' + arg)
|
2011-11-09 02:07:51 +00:00
|
|
|
else:
|
2013-03-08 21:53:35 +00:00
|
|
|
self.api.information('No one to kick :(', 'Info')
|