Gundula-7.3/bot.py

109 lines
3.4 KiB
Python

import os
from discord.ext import commands
import discord
from dotenv import load_dotenv
import textgen
max_len = 5
models = dict()
for textname in [
'faust',
'papageien',
# 'harrypotter-en',
'nathan',
# 'niebelungen',
]:
with open(f'text-{textname}.txt', 'r', encoding='utf-8') as f:
training_text = f.read()
models[textname] = textgen.train(training_text, max_len=max_len)
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
bot = commands.Bot(command_prefix='-', intents=discord.Intents.all())
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
@bot.command(name='isthis')
async def isthis_command(ctx, person, schmetterling, frage):
await ctx.send(f"https://api.memegen.link/images/pigeon/{person}/{schmetterling}/{frage}.png")
@bot.command(name='pictures')
async def pictures_command(ctx, a, auch_a, person):
await ctx.send(f"https://api.memegen.link/images/same/{a}/{auch_a}/{person}.png")
@bot.command(name='drake')
async def drake_command(ctx, no, yes):
await ctx.send(f"https://api.memegen.link/images/drake/{no}/{yes}.jpg")
@bot.command(name='obiwan')
async def obiwan_command(ctx, zitat):
await ctx.send(f"https://api.memegen.link/images/chosen/{zitat}.png")
@bot.command(name='picard')
async def picard_command(ctx, oben, unten):
await ctx.send(f"https://api.memegen.link/images/facepalm/{oben}/{unten}.png")
@bot.command(name='umdreh')
async def umdreh_command(ctx, yay, kerl, nay):
await ctx.send(f"https://api.memegen.link/images/db/{yay}/{kerl}/{nay}.png")
@bot.command(name='changemind')
async def changemind_command(ctx, these):
await ctx.send(f"https://api.memegen.link/images/cmm/{these}.png")
@bot.command(name='boromir')
async def boromir_command(ctx, notsimply, mordor):
await ctx.send(f"https://api.memegen.link/images/mordor/{notsimply}/{mordor}.png")
@bot.command(name='brains')
async def brains_command(ctx, eins, zwei, drei, pfier):
await ctx.send(f"https://api.memegen.link/images/gb/{eins}/{zwei}/{drei}/{pfier}.png")
@bot.command(name='summonbeleidiger')
async def summonbeleidiger_command(ctx):
await ctx.send("+beleidiger")
@bot.command(name='faust')
async def faust_command(ctx, *args):
model = models['faust']
current_text = " ".join(args)
n_lines = 500
for _ in range(n_lines):
current_text += textgen.query(model, current_text[-max_len:])
await ctx.send(current_text)
@bot.command(name='faustmeme')
async def faustmeme_command(ctx, current_text):
model = models['faust']
current_text = current_text.replace('-', ' ')
n_lines = 100
for _ in range(n_lines):
current_text += textgen.query(model, current_text[-max_len:])
current_text = current_text.replace('-', '--').replace('\n', '-').replace(' ', '-')
await ctx.send(f"https://api.memegen.link/images/chosen/{current_text}.png")
@bot.command(name='textgen')
async def textgen_command(ctx, *args):
args = list(args) # pop should work
textname = args.pop(0)
if textname.lower() in models.keys():
model = models[textname]
current_text = " ".join(args)
n_lines = 500
for _ in range(n_lines):
current_text += textgen.query(model, current_text[-max_len:])
await ctx.send(current_text)
else:
await ctx.send(f"Was zur Hölle soll {textname} bedeuten?")
bot.run(TOKEN)