More docs to the discord bot
This commit is contained in:
+10
-3
@@ -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"<https://github.com/klemek/meme-otron/tree/master/discord>")
|
||||
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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
+23
-24
@@ -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"<br>alt: {', '.join(meme.aliases)}"
|
||||
if meme.info is not None:
|
||||
info_line += f"<br><a href='{meme.info}' target='_blank'>more info</a>"
|
||||
info_line += "|"
|
||||
img_line += f"" \
|
||||
f"<a href='./templates/{meme.template}' target='_blank'>" \
|
||||
f"<img alt='enlarge' src='./preview/{meme.template}'/>" \
|
||||
f"</a>|"
|
||||
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"<br>alt: {', '.join(meme.aliases)}"
|
||||
if meme.info is not None:
|
||||
info_line += f"<br><a href='{meme.info}' target='_blank'>more info</a>"
|
||||
info_line += "|"
|
||||
img_line += f"" \
|
||||
f"<a href='./templates/{meme.template}' target='_blank'>" \
|
||||
f"<img alt='enlarge' src='./preview/{meme.template}'/>" \
|
||||
f"</a>|"
|
||||
print(i, meme_id)
|
||||
|
||||
doc_content += "|" * (COLUMNS - (i % COLUMNS))
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
+5
-6
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user