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))
|
debug(message, str(args))
|
||||||
if len(args) == 0 or args[0].lower().strip() == "help":
|
if len(args) == 0 or args[0].lower().strip() == "help":
|
||||||
await message.channel.send(f"Hey {message.author.mention},\n"
|
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"```\n"
|
||||||
f"[template] \"text 1\" \"text 2\" ...\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"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>")
|
f"<https://github.com/klemek/meme-otron/tree/master/discord>")
|
||||||
return
|
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 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 mid in SENT and len(SENT[mid]) > 0 and await delete(SENT[mid][-1]):
|
||||||
if not direct:
|
if not direct:
|
||||||
@@ -157,6 +163,7 @@ async def on_message(message):
|
|||||||
if not direct:
|
if not direct:
|
||||||
await delete(message)
|
await delete(message)
|
||||||
|
|
||||||
|
|
||||||
# Launch client and rerun on errors
|
# Launch client and rerun on errors
|
||||||
while True:
|
while True:
|
||||||
try:
|
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 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
|
> * 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
|
## List of templates
|
||||||
|
|
||||||
You can find here the full 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(dst_dir)
|
||||||
make_empty(prev_dir)
|
make_empty(prev_dir)
|
||||||
|
|
||||||
ids = sorted(meme_db.DATA.keys())
|
ids = sorted(meme_db.LIST)
|
||||||
|
|
||||||
doc_content = "|" * (COLUMNS + 1) \
|
doc_content = "|" * (COLUMNS + 1) \
|
||||||
+ "\n|" + ":---:|" * COLUMNS
|
+ "\n|" + ":---:|" * COLUMNS
|
||||||
@@ -42,29 +42,28 @@ img_line = None
|
|||||||
i = None
|
i = None
|
||||||
for i, meme_id in enumerate(ids):
|
for i, meme_id in enumerate(ids):
|
||||||
meme = meme_db.get_meme(meme_id)
|
meme = meme_db.get_meme(meme_id)
|
||||||
if meme is not None:
|
img = imgf.make(meme.template, meme.texts, debug=True)
|
||||||
img = imgf.make(meme.template, meme.texts, debug=True)
|
if img is not None:
|
||||||
if img is not None:
|
img.save(path.join(dst_dir, meme.template))
|
||||||
img.save(path.join(dst_dir, meme.template))
|
size = (round(img.size[0] * IMG_HEIGHT / img.size[1]), IMG_HEIGHT)
|
||||||
size = (round(img.size[0] * IMG_HEIGHT / img.size[1]), IMG_HEIGHT)
|
img2 = img.resize(size, resample=PIL.Image.LANCZOS)
|
||||||
img2 = img.resize(size, resample=PIL.Image.LANCZOS)
|
img2.save(path.join(prev_dir, meme.template))
|
||||||
img2.save(path.join(prev_dir, meme.template))
|
if i % COLUMNS == 0:
|
||||||
if i % COLUMNS == 0:
|
if info_line is not None and img_line is not None:
|
||||||
if info_line is not None and img_line is not None:
|
doc_content += info_line + img_line
|
||||||
doc_content += info_line + img_line
|
info_line = "\n|"
|
||||||
info_line = "\n|"
|
img_line = "\n|"
|
||||||
img_line = "\n|"
|
info_line += f"**{meme_id}**"
|
||||||
info_line += f"**{meme_id}**"
|
if len(meme.aliases) > 0:
|
||||||
if len(meme.aliases) > 0:
|
info_line += f"<br>alt: {', '.join(meme.aliases)}"
|
||||||
info_line += f"<br>alt: {', '.join(meme.aliases)}"
|
if meme.info is not None:
|
||||||
if meme.info is not None:
|
info_line += f"<br><a href='{meme.info}' target='_blank'>more info</a>"
|
||||||
info_line += f"<br><a href='{meme.info}' target='_blank'>more info</a>"
|
info_line += "|"
|
||||||
info_line += "|"
|
img_line += f"" \
|
||||||
img_line += f"" \
|
f"<a href='./templates/{meme.template}' target='_blank'>" \
|
||||||
f"<a href='./templates/{meme.template}' target='_blank'>" \
|
f"<img alt='enlarge' src='./preview/{meme.template}'/>" \
|
||||||
f"<img alt='enlarge' src='./preview/{meme.template}'/>" \
|
f"</a>|"
|
||||||
f"</a>|"
|
print(i, meme_id)
|
||||||
print(i, meme_id)
|
|
||||||
|
|
||||||
doc_content += "|" * (COLUMNS - (i % COLUMNS))
|
doc_content += "|" * (COLUMNS - (i % COLUMNS))
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ DATA_FILE = utils.relative_path(__file__, "..", "memes.json")
|
|||||||
|
|
||||||
DATA = {}
|
DATA = {}
|
||||||
ALIASES = {}
|
ALIASES = {}
|
||||||
|
LIST = []
|
||||||
|
|
||||||
logger = logging.getLogger("meme_db")
|
logger = logging.getLogger("meme_db")
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ def load_item(i, item):
|
|||||||
:param (int) i:
|
:param (int) i:
|
||||||
:param (dict) item:
|
:param (dict) item:
|
||||||
"""
|
"""
|
||||||
|
global LIST
|
||||||
item_id = ""
|
item_id = ""
|
||||||
try:
|
try:
|
||||||
if not (isinstance(item, dict)):
|
if not (isinstance(item, dict)):
|
||||||
@@ -102,6 +104,7 @@ def load_item(i, item):
|
|||||||
else:
|
else:
|
||||||
DATA[item_id] = meme
|
DATA[item_id] = meme
|
||||||
if not meme.abstract:
|
if not meme.abstract:
|
||||||
|
LIST += [item_id]
|
||||||
ALIASES[item_id] = item_id
|
ALIASES[item_id] = item_id
|
||||||
for alias in meme.aliases:
|
for alias in meme.aliases:
|
||||||
if alias in ALIASES:
|
if alias in ALIASES:
|
||||||
|
|||||||
+5
-6
@@ -28,11 +28,10 @@ while True:
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
meme_db.load_memes(purge=True)
|
meme_db.load_memes(purge=True)
|
||||||
count = 0
|
count = 0
|
||||||
for meme_id in meme_db.DATA:
|
for meme_id in meme_db.LIST:
|
||||||
meme = meme_db.get_meme(meme_id)
|
meme = meme_db.get_meme(meme_id)
|
||||||
if meme is not None:
|
img = imgf.make(meme.template, meme.texts, debug=True)
|
||||||
img = imgf.make(meme.template, meme.texts, debug=True)
|
if img is not None:
|
||||||
if img is not None:
|
img.save(path.join(dst_dir, meme.template))
|
||||||
img.save(path.join(dst_dir, meme.template))
|
count += 1
|
||||||
count += 1
|
|
||||||
print(f"{datetime.datetime.now():%H:%M:%S} / {count} registered templates / {len(os.listdir(templates_dir))} files")
|
print(f"{datetime.datetime.now():%H:%M:%S} / {count} registered templates / {len(os.listdir(templates_dir))} files")
|
||||||
|
|||||||
Reference in New Issue
Block a user