ai-bot/aitrain.py

54 lines
1.7 KiB
Python
Raw Normal View History

2021-05-21 11:47:19 +00:00
from textgenrnn import textgenrnn
import discord
from discord.ext import commands
import regex as re
import functools
2021-05-21 11:47:19 +00:00
textgen = textgenrnn(name="insert3")
client = commands.Bot(command_prefix='.')
boton = False
def add_to_train(clean_content):
print(clean_content)
with open("train.txt", "a") as train:
train.write(f"{clean_content} \n")
2021-05-21 11:47:19 +00:00
@client.event
async def on_message(message):
await client.process_commands(message)
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',message.content.lower())
if not message.attachments:
if boton:
2021-05-21 11:47:19 +00:00
if message.content.lower().startswith("$"):
pass
elif urls:
pass
elif message.author.bot:
pass
elif message.content.lower().startswith("p!"):
pass
elif message.content.lower().startswith(""):
pass
else:
2021-05-21 16:40:44 +00:00
writing_function = functools.partial(add_to_train, message.clean_content)
2021-05-22 00:21:56 +00:00
await client.loop.run_in_executor(None, writing_function)
2021-05-21 11:47:19 +00:00
@commands.is_owner()
2021-05-21 11:47:19 +00:00
@client.command()
async def train(ctx):
global boton
boton = True
await ctx.send("I am now training what to say based on your messages")
2021-05-21 11:47:19 +00:00
@commands.is_owner()
2021-05-21 11:47:19 +00:00
@client.command()
async def stopbot(ctx):
async with ctx.typing:
training_function = functools.partial(textgen.train_from_file, 'train.txt', num_epochs=11)
2021-05-22 00:21:56 +00:00
await client.loop.run_in_executor(None, training_function)
await ctx.send("data collection done, I will now log of discord and build an a.i")
2021-05-22 00:21:56 +00:00
await client.logout()
2021-05-21 11:47:19 +00:00
2021-05-21 11:48:13 +00:00
client.run('BOTTOKEN')