diff --git a/discord_bot/__main__.py b/discord_bot/__main__.py index 92cce88..bac1c7c 100644 --- a/discord_bot/__main__.py +++ b/discord_bot/__main__.py @@ -100,14 +100,20 @@ async def on_message(message): debug(message, str(args)) if len(args) == 0 or args[0].lower().strip() == "help": await message.channel.send(f"Hey {message.author.mention},\n" - f"You can generate a meme with the syntax\n" + f"You can generate a meme with the syntax:\n" f"```\n" f"[template] \"text 1\" \"text 2\" ...\n" - f"```\n" + f"```" f"I also work with DM to keep your server clean of spam.\n" - f"You can find a more detailed help and a list of templates at:\n" + f"Use `delete` to remove my last message\n" + f"Use `list` to get a simple list\n" + f"You can find a more detailed help and a full list of templates at:\n" f"") return + if len(args) > 0 and args[0].lower().strip() == "list": + await message.channel.send(f"Here is a list of all known templates:\n" + f"```{', '.join(db.LIST)}```") + return if len(args) > 0 and args[0].lower().strip() == "delete": if mid in SENT and len(SENT[mid]) > 0 and await delete(SENT[mid][-1]): if not direct: @@ -157,6 +163,7 @@ async def on_message(message): if not direct: await delete(message) + # Launch client and rerun on errors while True: try: diff --git a/docs/README.md b/docs/README.md index 38c2869..50faf3a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,6 +15,18 @@ Depending of the number of `"text"` arguments, several behavior occurs: > * You don't have to use all texts shown on templates > * You can use an empty text argument ( `""` ) to skip a text and keep it blank +## Discord features + +Tag the bot and use the above syntax to get started. In addition, you can use the following commands: + +* Use `help` to get a simple help message +* Use `list` to get a list of all meme ids +* Use `delete` to delete the last message sent by the bot (directed to you) + +Enjoy the full experience of this bot by using direct messages to keep your server free of spam. + + + ## List of templates You can find here the full list of templates. diff --git a/docs/build.py b/docs/build.py index 1a1e777..ffc4a9c 100644 --- a/docs/build.py +++ b/docs/build.py @@ -31,7 +31,7 @@ def make_empty(target_dir): make_empty(dst_dir) make_empty(prev_dir) -ids = sorted(meme_db.DATA.keys()) +ids = sorted(meme_db.LIST) doc_content = "|" * (COLUMNS + 1) \ + "\n|" + ":---:|" * COLUMNS @@ -42,29 +42,28 @@ img_line = None i = None for i, meme_id in enumerate(ids): meme = meme_db.get_meme(meme_id) - if meme is not None: - img = imgf.make(meme.template, meme.texts, debug=True) - if img is not None: - img.save(path.join(dst_dir, meme.template)) - size = (round(img.size[0] * IMG_HEIGHT / img.size[1]), IMG_HEIGHT) - img2 = img.resize(size, resample=PIL.Image.LANCZOS) - img2.save(path.join(prev_dir, meme.template)) - if i % COLUMNS == 0: - if info_line is not None and img_line is not None: - doc_content += info_line + img_line - info_line = "\n|" - img_line = "\n|" - info_line += f"**{meme_id}**" - if len(meme.aliases) > 0: - info_line += f"
alt: {', '.join(meme.aliases)}" - if meme.info is not None: - info_line += f"
more info" - info_line += "|" - img_line += f"" \ - f"" \ - f"enlarge" \ - f"|" - print(i, meme_id) + img = imgf.make(meme.template, meme.texts, debug=True) + if img is not None: + img.save(path.join(dst_dir, meme.template)) + size = (round(img.size[0] * IMG_HEIGHT / img.size[1]), IMG_HEIGHT) + img2 = img.resize(size, resample=PIL.Image.LANCZOS) + img2.save(path.join(prev_dir, meme.template)) + if i % COLUMNS == 0: + if info_line is not None and img_line is not None: + doc_content += info_line + img_line + info_line = "\n|" + img_line = "\n|" + info_line += f"**{meme_id}**" + if len(meme.aliases) > 0: + info_line += f"
alt: {', '.join(meme.aliases)}" + if meme.info is not None: + info_line += f"
more info" + info_line += "|" + img_line += f"" \ + f"" \ + f"enlarge" \ + f"|" + print(i, meme_id) doc_content += "|" * (COLUMNS - (i % COLUMNS)) diff --git a/meme_otron/meme_db.py b/meme_otron/meme_db.py index ef178b2..b47d37b 100644 --- a/meme_otron/meme_db.py +++ b/meme_otron/meme_db.py @@ -8,6 +8,7 @@ DATA_FILE = utils.relative_path(__file__, "..", "memes.json") DATA = {} ALIASES = {} +LIST = [] logger = logging.getLogger("meme_db") @@ -45,6 +46,7 @@ def load_item(i, item): :param (int) i: :param (dict) item: """ + global LIST item_id = "" try: if not (isinstance(item, dict)): @@ -102,6 +104,7 @@ def load_item(i, item): else: DATA[item_id] = meme if not meme.abstract: + LIST += [item_id] ALIASES[item_id] = item_id for alias in meme.aliases: if alias in ALIASES: diff --git a/tools/live_edit.py b/tools/live_edit.py index bddf71b..41d8a0b 100644 --- a/tools/live_edit.py +++ b/tools/live_edit.py @@ -28,11 +28,10 @@ while True: time.sleep(0.1) meme_db.load_memes(purge=True) count = 0 - for meme_id in meme_db.DATA: + for meme_id in meme_db.LIST: meme = meme_db.get_meme(meme_id) - if meme is not None: - img = imgf.make(meme.template, meme.texts, debug=True) - if img is not None: - img.save(path.join(dst_dir, meme.template)) - count += 1 + img = imgf.make(meme.template, meme.texts, debug=True) + if img is not None: + img.save(path.join(dst_dir, meme.template)) + count += 1 print(f"{datetime.datetime.now():%H:%M:%S} / {count} registered templates / {len(os.listdir(templates_dir))} files")