From ca3cb8fae0a5883973ca84d61c2602c7ab3637e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 25 Dec 2021 00:47:37 +0100 Subject: impromptu: pronounceable MUC names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/core/core.py | 3 ++- poezio/utils.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 poezio/utils.py diff --git a/poezio/core/core.py b/poezio/core/core.py index ffdd11d1..17e352de 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -42,6 +42,7 @@ from poezio import events from poezio import theming from poezio import timed_events from poezio import windows +from poezio import utils from poezio.bookmarks import ( BookmarkList, @@ -1005,7 +1006,7 @@ class Core: return nick = self.own_nick - localpart = uuid.uuid4().hex + localpart = utils.pronounceable() room_str = '{!s}@{!s}'.format(localpart, default_muc) try: room = JID(room_str) diff --git a/poezio/utils.py b/poezio/utils.py new file mode 100644 index 00000000..124d2002 --- /dev/null +++ b/poezio/utils.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" + Utilities +""" + +from random import choice + +VOWELS = 'aiueo' +CONSONANTS = 'bcdfghjklmnpqrstvwxz' + + +def pronounceable(length: int = 6) -> str: + """Generates a pronounceable name""" + out = '' + vowels = choice((True, False)) + for _ in range(0, length): + out += choice(VOWELS if vowels else CONSONANTS) + vowels = not vowels + return out -- cgit v1.2.3