try: roomsdb = pickle.load(open(roomsfile, "rb")) except FileNotFoundError: roomsdb = {} if room_id in allowed_rooms and room_id in roomsdb.keys(): # Remove special characters before translation message = sub('[^A-z0-9\-\.\?!:\sÄäÜüÖö]+', '', message) trans = googletrans.Translator() logger.debug(f"Detecting language for message: {message}") message_source_lang = trans.detect(message).lang if roomsdb[room_id]["bidirectional"]: languages = [roomsdb[room_id]["source_langs"][0], roomsdb[room_id["dest_lang"]]] if message_source_lang in languages: # there has to be a simpler way, but my brain is tired dest_lang = set(languages).difference([message_source_lang]) if len(dest_lang) == 1: dest_lang = dest_lang.pop() translated = trans.translate(message, dest=dest_lang).text await send_text_to_room(client, room_id, translated) else: if message_source_lang != roomsdb[room_id]["dest_lang"] and (roomsdb[room_id]["source_langs"] == ['any'] or message_source_lang in roomsdb[room_id]["source_langs"]): translated = trans.translate(message, dest=roomsdb[room_id]["dest_lang"]).text await send_text_to_room(client, room_id, translated) plugin = Plugin("translate", "General", "Provide near-realtime translations of all room-messages via Google Translate") plugin.add_command("translate", switch, "`translate [[bi] source_lang... dest_lang]` - translate text from " "one or more source_lang to dest_lang", allowed_rooms) plugin.add_hook("m.room.message", translate, allowed_rooms)
7: f"<font color=\"red\">fairly</font> {condition}", 8: f"<font color=\"red\">pretty darn</font> {condition}", 9: f"<font color=\"red\">extremely</font> {condition}", 10: f"the {condition}est of all! {nick} scores a <font color=\"red\">perfect</font> 10 on the {condition.replace(' ', '-')}-o-meter!! I bow to {nick}'s" f" {condition}ness...", } return comments[level] async def meter(command): try: nick = command.args[0] condition = " ".join(command.args[1:]) if not condition: raise IndexError else: level: int = random.randint(0, 10) text: str = f"{condition.replace(' ', '-')}-o-Meter {build_gauge(level)} <font color=\"{get_level_color(level)}\">{str(level)}</font>/10 {nick} is " \ f"{get_comment(level, nick, condition)}" await send_typing(command.client, command.room.room_id, text) except (ValueError, IndexError): await send_text_to_room(command.client, command.room.room_id, "Usage: `meter <target> <condition>`") plugin = Plugin("meter", "General", "Plugin to provide a simple, randomized !meter") plugin.add_command("meter", meter, "accurately measure someones somethingness")
"Mit etwas Gl\xfcck schon.", "Das ist nicht klar.", "Die Zeichen stehen sehr gut!", "Nein, auf gar keinen Fall!", "Ja, ja, ja!", "Das ist nicht Ihr Ernst?!", "Das ist ziemlich sicher.", "Fragen Sie in ein paar Wochen nochmal nach.", "Wenn Sie daran glauben wollen, bitte ...", "Ich w\xfcrde nicht darauf wetten", "Wenn Sie sich anstrengen, schon ...", "Die Aussicht ist gut.", "M\xf6glich w\xe4re es durchaus.", "Nicht um alles auf der Welt!", "Daran sollten Sie nicht mal denken.", "Haben Sie etwas Geduld.", "Ich zweifele nicht daran.", "Ein definitives Ja.", "Vielleicht...", "Warum nicht?", "Unter Umst\xe4nden schon.", "Es k\xf6nnte bald Wirklichkeit werden.", "Die Zeit wird es zeigen.", ) message = "**Antwort:** " + random.choice(oracles) await send_typing(command.client, command.room.room_id, message) plugin = Plugin("oracle", "General", "Plugin to provide a simple, randomized !oracle") plugin.add_command("oracle", oracle, "predict the inevitable future")
try: roomsdb = pickle.load(open(roomsfile, "rb")) except FileNotFoundError: roomsdb = {} if room_id in allowed_rooms and room_id in roomsdb.keys(): # Remove special characters before translation message = sub('[^A-z0-9\-\.\?!:\sÄäÜüÖö]+', '', message) trans = googletrans.Translator() logger.debug(f"Detecting language for message: {message}") message_source_lang = trans.detect(message).lang if roomsdb[room_id]["bidirectional"]: languages = [roomsdb[room_id]["source_langs"][0], roomsdb[room_id["dest_lang"]]] if message_source_lang in languages: # there has to be a simpler way, but my brain is tired dest_lang = set(languages).difference([message_source_lang]) if len(dest_lang) == 1: dest_lang = dest_lang.pop() translated = trans.translate(message, dest=dest_lang).text await send_text_to_room(client, room_id, translated) else: if message_source_lang != roomsdb[room_id]["dest_lang"] and (roomsdb[room_id]["source_langs"] == ['any'] or message_source_lang in roomsdb[room_id]["source_langs"]): translated = trans.translate(message, dest=roomsdb[room_id]["dest_lang"]).text await send_text_to_room(client, room_id, translated) plugin = Plugin("translate", "General", "Provide near-realtime translations of all room-messages via Google Translate") plugin.add_command("translate", switch, "`translate [[bi] source_lang... dest_lang]` - translate text from " "one or more source_lang to dest_lang", room_id=allowed_rooms, power_level=power_level) plugin.add_hook("m.room.message", translate, room_id=allowed_rooms)
text = "%u picks a flower. As its sweet smell fills the channel, all chatter get +3 for saving throws on net splits." elif onlypick == "nose": text = "Eeeew! %u, do that somewhere private!" elif onlypick in ("fight", "a fight"): text = "%u starts a brawl in another channel. Only the quick reaction of fellow %c chatters saves the weakling from a gruesome fate." elif onlypick == "pocket": text = "Despite being amazingly clumsy, %u manages to pick the pocket of an innocent bystander. A used handkerchief is the reward." elif onlypick == "lock": text = "Lockpick required." else: text = random.choice(texts) chosen = random.choice(picks) if picks != [""]: msg = text # msg = msg.replace("%u", event.user) # msg = msg.replace("%c", str(event.channel)) msg = msg.replace("%S", "**" + chosen.upper() + "**") msg = msg.replace("%s", "**" + chosen + "**") msg = msg.replace("%N", chosen.upper()) msg = msg.replace("%n", chosen) else: return None await send_typing(command.client, command.room.room_id, msg) plugin = Plugin("pick", "General", "Plugin to provide a simple, randomized !pick") plugin.add_command("pick", pick, "aids you in those really important life decisions")
for (plugin_command_name, plugin_command ) in requested_plugin.get_commands().items(): command_texts.append( (plugin_command_name, plugin_command.help_text)) headline: str = f"**Plugin {requested_plugin.name}**" help_text = build_sorted_text_output( headline, command_texts) else: # Plugin is not valid for the room raise ValueError else: # Plugin does not exist raise ValueError except ValueError: help_text = "Plugin not active (in this room), try `help`" else: # too many arguments or invalid plugin-name help_text = "try `help` ;-)" await send_text_to_room(command.client, current_room_id, help_text) plugin = Plugin("help", "General", "Provide helpful help") plugin.add_command("help", print_help, "Display list of all available commands")
"Number of dice or sides per die are zero! Please use only nonzero numbers." ) return None random.seed() roll_list = [] if number > 100000: await send_typing( command.client, command.room.room_id, "Number of dice too large! Try a more reasonable number. (5 digits are fine)" ) return None for _ in range(number): roll_list.append(random.randint(lowest_value, sides)) if len(roll_list) > 50: result_list = " <detailed list too large>" else: result_list = " (" + " + ".join([str(x) for x in roll_list]) + ")" if len(result_list) > 200: result_list = " <detailed list too large>" if len(roll_list) == 1: result_list = "" await send_typing( command.client, command.room.room_id, "**Result:** " + str(sum(roll_list) + modifier) + result_list) plugin = Plugin("roll", "General", "Plugin to provide a simple, randomized !roll of dice") plugin.add_command("roll", roll, "the dice giveth and the dice taketh away")
from plugin import Plugin from chat_functions import send_typing import random import os.path async def spruch(command): with open(os.path.join(os.path.dirname(__file__), "spruchdb.txt")) as spruchdb: sprueche = spruchdb.readlines() message = random.choice(sprueche) await send_typing(command.client, command.room.room_id, message) plugin = Plugin("spruch", "General", "Plugin to provide a simple, randomized !spruch") plugin.add_command("spruch", spruch, "famous quotes from even more famous people")
from chat_functions import send_typing from plugin import Plugin async def echo(command): """Echo back the command's arguments""" response = " ".join(command.args) await send_typing(command.client, command.room.room_id, response) plugin = Plugin("echo", "General", "A very simple Echo plugin") plugin.add_command( "echo", echo, "make someone agree with you for once", ["!iAxDarGKqYCIKvNSgu:pack.rocks", "!WLzPcYhULnmsuPwZSN:pack.rocks"]) plugin.add_command( "echo2", echo, "make someone agree with you for once - again", ["!iAxDarGKqYCIKvNSgu:pack.rocks", "!WLzPcYhULnmsuPwZSN:pack.rocks"])