Add a cyberplugin
This commit is contained in:
parent
af0fe9d2e4
commit
1914cfe003
3 changed files with 52 additions and 0 deletions
6
doc/source/plugins/cyber.rst
Normal file
6
doc/source/plugins/cyber.rst
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.. _cyber-plugin:
|
||||||
|
|
||||||
|
Cyber
|
||||||
|
=====
|
||||||
|
|
||||||
|
.. automodule:: cyber
|
|
@ -87,6 +87,11 @@ Plugin index
|
||||||
|
|
||||||
Close all tabs except MUCs and the roster.
|
Close all tabs except MUCs and the roster.
|
||||||
|
|
||||||
|
Cyber
|
||||||
|
:ref:`Documentation <cyber-plugin>`
|
||||||
|
|
||||||
|
Add a cybertouch to your messages.
|
||||||
|
|
||||||
Day Change
|
Day Change
|
||||||
:ref:`Documentation <daychange-plugin>`
|
:ref:`Documentation <daychange-plugin>`
|
||||||
|
|
||||||
|
@ -297,3 +302,4 @@ Plugin index
|
||||||
pipe_cmd
|
pipe_cmd
|
||||||
close_all
|
close_all
|
||||||
reorder
|
reorder
|
||||||
|
cyber
|
||||||
|
|
40
plugins/cyber.py
Normal file
40
plugins/cyber.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
"""
|
||||||
|
This plugin adds a "cyber" prefix to a random word in your chatroom messages.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
Say something in a MUC tab.
|
||||||
|
|
||||||
|
Configuration options
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
.. glossary::
|
||||||
|
|
||||||
|
frequency
|
||||||
|
**Default:** ``10``
|
||||||
|
|
||||||
|
The percentage of the time the plugin will activate (randomly). 100 for every message, <= 0 for never.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from plugin import BasePlugin
|
||||||
|
from random import choice, randint
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_CONFIG = {'cyber': {'frequency': 10}}
|
||||||
|
|
||||||
|
class Plugin(BasePlugin):
|
||||||
|
|
||||||
|
default_config = DEFAULT_CONFIG
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
self.api.add_event_handler('muc_say', self.cyberize)
|
||||||
|
|
||||||
|
def cyberize(self, msg, tab):
|
||||||
|
if randint(1, 100) > self.config.get('frequency'):
|
||||||
|
return
|
||||||
|
words = [word for word in re.split('\W+', msg['body']) if len(word) > 3]
|
||||||
|
if words:
|
||||||
|
word = choice(words)
|
||||||
|
msg['body'] = msg['body'].replace(word, 'cyber' + word)
|
Loading…
Reference in a new issue