2013-05-01 16:45:32 +00:00
|
|
|
"""
|
2016-10-03 22:26:54 +00:00
|
|
|
This plugin makes you have a random nick when joining a chatroom.
|
2013-05-01 16:45:32 +00:00
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
|
|
|
To have a random nick, just join a room with “RANDOM” as your nick. It will
|
|
|
|
automatically be changed to something random, for example: ::
|
|
|
|
|
|
|
|
/join coucou@conference.example.com/RANDOM
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.plugin import BasePlugin
|
2013-05-01 16:45:32 +00:00
|
|
|
from random import choice
|
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
2013-05-01 16:45:32 +00:00
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
|
|
|
self.api.add_event_handler('joining_muc', self.change_nick_to_random)
|
2013-05-09 11:16:19 +00:00
|
|
|
self.api.add_event_handler('changing_nick', self.change_nick_to_random)
|
2013-05-01 16:45:32 +00:00
|
|
|
|
|
|
|
def change_nick_to_random(self, presence):
|
|
|
|
to = presence["to"]
|
2013-05-01 16:52:29 +00:00
|
|
|
if to.resource == 'RANDOM':
|
|
|
|
to.resource = gen_nick(3)
|
|
|
|
presence["to"] = to
|
2013-05-01 16:45:32 +00:00
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
2013-05-01 16:45:32 +00:00
|
|
|
s = ["i", "ou", "ou", "on", "a", "o", "u", "i"]
|
2018-08-15 11:13:17 +00:00
|
|
|
c = [
|
|
|
|
"b", "c", "d", "f", "g", "h", "j", "k", "m", "l", "n", "p", "r", "s", "t",
|
|
|
|
"v", "z"
|
|
|
|
]
|
|
|
|
|
2013-05-01 16:45:32 +00:00
|
|
|
|
|
|
|
def gen_nick(size):
|
|
|
|
res = ''
|
2016-07-06 07:49:40 +00:00
|
|
|
for _ in range(size):
|
2013-05-01 16:45:32 +00:00
|
|
|
res += '%s%s' % (choice(c), choice(s))
|
|
|
|
return res
|