erster commit

This commit is contained in:
Tristan Schneider 2023-02-05 16:58:06 +01:00
commit aaeafd585f
2 changed files with 16904 additions and 0 deletions

103
bot.py Normal file
View File

@ -0,0 +1,103 @@
import os
from discord.ext import commands
from dotenv import load_dotenv
import random
max_len = 6
with open('text-faust.txt', 'r', encoding='utf-8') as f:
training_text = f.read()
def train(text, max_len=5):
model = dict()
for i in range(1, max_len+1):
model[i] = dict()
for k in range(len(text) - i - 1):
if not text[k:k+i] in model[i]:
model[i][text[k:k+i]] = dict()
if text[k+i] in model[i][text[k:k+i]]:
model[i][text[k:k+i]][text[k+i]] += 1
else:
model[i][text[k:k+i]][text[k+i]] = 1
return model
def query(model, previous):
for l in range(len(previous), 0, -1):
if previous[-l:] not in model[l]:
continue
freqs = model[l][previous[-l:]]
return random.choices(list(freqs.keys()), list(freqs.values()))[0]
#return random.choices(list(freqs.keys()))[0]
model = train(training_text, max_len=max_len)
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
bot = commands.Bot(command_prefix='-')
@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 test(ctx):
await ctx.send("+beleidiger")
@bot.command(name='faust')
async def test(ctx, current_text):
n_lines = 500
for _ in range(n_lines):
current_text += query(model, current_text[-6:])
await ctx.send(current_text)
@bot.command(name='faustmeme')
async def test(ctx, current_text):
current_text = current_text.replace('-', ' ')
n_lines = 100
for _ in range(n_lines):
current_text += query(model, current_text[-6:])
current_text = current_text.replace('-', '--').replace('\n', '-').replace(' ', '-')
await ctx.send(f"https://api.memegen.link/images/chosen/{current_text}.png""")
bot.run(TOKEN)

16801
text-faust.txt Normal file

File diff suppressed because it is too large Load Diff