-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (69 loc) · 2.64 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#coding: utf-8
import discord
import datetime
import asyncio
import markov
import os
import dotenv
import cursed
import image_generator
from discord.ext import commands
from random import choice
env = dotenv.getenv()
current_path = os.path.abspath(os.path.dirname(__file__))
# listing the available assets
images = list(os.listdir(os.path.join(current_path, 'res/images')))
fonts = list(os.listdir(os.path.join(current_path, 'res/fonts')))
# initializing the markov chain
markov_chain = markov.markov(os.path.join(current_path,'res/idezetek'), 6)
def _get_random_image():
return os.path.join(current_path, "res/images/" + choice(images))
def _get_duck_image(keywords):
return image_generator.download_image(keywords)
def _get_random_font():
return os.path.join(current_path, "res/fonts/" + choice(fonts))
def _generate_quote_image():
quote = markov_chain.generate_text()
return (image_generator.generate(_get_random_image(), _get_random_font(), quote))
def _create_quote_image(user_text, font_size):
return (image_generator.generate(_get_random_image(), _get_random_font(), user_text, font_size))
def _create_custom_quote_image(user_text, keywords, font_size):
duck_image = _get_duck_image(keywords)
if not duck_image:
return None
generated_image = image_generator.generate(duck_image, _get_random_font(), user_text, font_size)
os.remove(duck_image)
return generated_image
client = commands.Bot(command_prefix="léci ")
@client.event
async def on_ready():
print("A bot elérhető!")
@client.command(aliases=["átkozott", "atkozot", "átkozot"])
async def atkozott(ctx):
response = cursed.get_cursed_image()
await (ctx.send(response))
@client.command(aliases=["motiváció", "Motiváció"])
async def motivacio(ctx):
response = _generate_quote_image()
await ctx.send(file=discord.File(response))
os.remove(response)
@client.command(aliases=["készít", "keszit", "Készíts", "készíts"])
async def keszits(ctx, user_text, search_terms=None, text_size=1):
if not search_terms:
response = _create_quote_image(user_text, text_size)
else:
try:
response = _create_custom_quote_image(user_text, search_terms, text_size)
except:
await ctx.send("A képpel hiba adódott :(")
for file in os.listdir(current_path):
if file.endswith('.jpg'):
os.remove(file)
return
if not response:
await ctx.send("Nincs találat :(")
return
await ctx.send(file=discord.File(response))
os.remove(response)
if __name__ == "__main__":
client.run(env.get("DISCORD_TOKEN"))