From 9082d0a40411a85856cc2ea6e37830d5eb61eec3 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 20 Sep 2016 20:49:33 +0000 Subject: [PATCH] Add mention --- yaboli/mention.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 yaboli/mention.py diff --git a/yaboli/mention.py b/yaboli/mention.py new file mode 100644 index 0000000..eda86ff --- /dev/null +++ b/yaboli/mention.py @@ -0,0 +1,43 @@ +class Mention(str): + """ + A class to compare @mentions to nicks and other @mentions + """ + + def mentionable(nick): + """ + A mentionable version of the nick. + Add an "@" in front to mention someone on euphoria. + """ + + # return "".join(c for c in nick if not c in ".!?;&<'\"" and not c.isspace()) + return "".join(filter(lambda c: c not in ".!?;&<'\"" and not c.isspace(), nick)) + + def __new__(cls, nick): + return str.__new__(cls, Mention.mentionable(nick)) + + def __add__(self, other): + return Mention(str(self) + other) + + def __mod__(self, other): + return Mention(str(self) % other) + + def __mul__(self, other): + return Mention(str(self)*other) + + def __repr__(self): + return "@" + super().__repr__() + + def __radd__(self, other): + return Mention(other + str(self)) + + def __rmul__(self, other): + return Mention(other*str(self)) + + def format(self, *args, **kwargs): + return Mention(str(self).format(*args, **kwargs)) + + def format_map(self, *args, **kwargs): + return Mention(str(self).format_map(*args, **kwargs)) + + def replace(self, *args, **kwargs): + return Mention(str(self).replace(*args, **kwargs))