more cleanup
This commit is contained in:
parent
5d50081fc3
commit
e200b9891c
1 changed files with 40 additions and 36 deletions
76
lulzbot.py
76
lulzbot.py
|
@ -1,12 +1,13 @@
|
||||||
motd =' \n\
|
motd ='''
|
||||||
_ _ ____ ___ _ \n\
|
_ _ ____ ___ _
|
||||||
| | _ _| | ___| __ ) / _ \| |_ \n\
|
| | _ _| | ___| __ ) / _ \| |_
|
||||||
| | | | | | | |_ / _ \| | | | __| \n\
|
| | | | | | | |_ / _ \| | | | __|
|
||||||
| |__| |_| | |___ / /| |_) | |_| | |_ \n\
|
| |__| |_| | |___ / /| |_) | |_| | |_
|
||||||
|_____\__,_|_____/___|____/ \___/ \__| \n\
|
|_____\__,_|_____/___|____/ \___/ \__|
|
||||||
'
|
'''
|
||||||
# Discord Bot
|
# Discord Bot
|
||||||
import discord, datetime, time
|
import discord, datetime, time
|
||||||
|
import numpy as np
|
||||||
from fortune import fortune
|
from fortune import fortune
|
||||||
from ligma import ligma
|
from ligma import ligma
|
||||||
from limericks import limerick
|
from limericks import limerick
|
||||||
|
@ -15,14 +16,42 @@ TOKEN = open('discord_token').read()
|
||||||
chuck = open('chucknorris').read().split('\n%\n')
|
chuck = open('chucknorris').read().split('\n%\n')
|
||||||
client = discord.Client(activity=discord.Game(name='with myself'))
|
client = discord.Client(activity=discord.Game(name='with myself'))
|
||||||
|
|
||||||
|
menu = '''```
|
||||||
|
Commands:
|
||||||
|
fortune: tell a fortune
|
||||||
|
chuck: give a Chuck Norris quote
|
||||||
|
ligma: LIGMA BALLS
|
||||||
|
bofa: deez
|
||||||
|
deez: nutz
|
||||||
|
limerick: tell a limerick
|
||||||
|
prost!: prost!
|
||||||
|
|
||||||
|
Contribute!
|
||||||
|
https://github.com/adoyle0/lulzbot```'''
|
||||||
|
|
||||||
# NLP
|
# NLP
|
||||||
import numpy as np
|
|
||||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
tokenizer = AutoTokenizer.from_pretrained('microsoft/DialoGPT-large')
|
tokenizer = AutoTokenizer.from_pretrained('microsoft/DialoGPT-large')
|
||||||
model = AutoModelForCausalLM.from_pretrained('../southpark/output-medium')
|
model = AutoModelForCausalLM.from_pretrained('../southpark/output-medium')
|
||||||
|
|
||||||
|
def cartman_speak(user_message):
|
||||||
|
new_user_input_ids = tokenizer.encode(user_message + tokenizer.eos_token, return_tensors='pt')
|
||||||
|
bot_output = new_user_input_ids
|
||||||
|
bot_input_ids = torch.cat([new_user_input_ids, bot_output])
|
||||||
|
bot_output = model.generate(
|
||||||
|
bot_input_ids, max_length= 200,
|
||||||
|
pad_token_id=tokenizer.eos_token_id,
|
||||||
|
no_repeat_ngram_size=3,
|
||||||
|
do_sample=True,
|
||||||
|
top_k=100,
|
||||||
|
top_p=0.7,
|
||||||
|
temperature=.8
|
||||||
|
)
|
||||||
|
|
||||||
|
return '{}'.format(tokenizer.decode(bot_output[:,bot_input_ids.shape[-1]:][0], skip_special_tokens=True))
|
||||||
|
|
||||||
# Twitter
|
# Twitter
|
||||||
import tweepy
|
import tweepy
|
||||||
|
|
||||||
|
@ -35,22 +64,9 @@ access_token_secret = twit_sekrit[4]
|
||||||
tclient = tweepy.Client(bearer_token,api_key,api_key_secret,access_token,access_token_secret)
|
tclient = tweepy.Client(bearer_token,api_key,api_key_secret,access_token,access_token_secret)
|
||||||
|
|
||||||
def user_tweet(twitter):
|
def user_tweet(twitter):
|
||||||
statuses = tclient.get_users_tweets(44196397, exclude=['replies'], max_results=5)
|
statuses = tclient.get_users_tweets(twitter, exclude=['replies'], max_results=5)
|
||||||
return statuses[0][0]
|
return statuses[0][0]
|
||||||
|
|
||||||
menu = '```\n\
|
|
||||||
Commands:\n\
|
|
||||||
fortune: tell a fortune\n\
|
|
||||||
chuck: give a Chuck Norris quote\n\
|
|
||||||
ligma: LIGMA BALLS\n\
|
|
||||||
bofa: deez\n\
|
|
||||||
deez: nutz\n\
|
|
||||||
limerick: tell a limerick\n\
|
|
||||||
prost!: prost!\n\
|
|
||||||
\n\
|
|
||||||
Contribute!\
|
|
||||||
https://github.com/adoyle0/lulzbot```'
|
|
||||||
|
|
||||||
# Init
|
# Init
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
|
@ -69,24 +85,12 @@ async def on_message(message):
|
||||||
|
|
||||||
if message.channel.name == 'cartman':
|
if message.channel.name == 'cartman':
|
||||||
async with message.channel.typing():
|
async with message.channel.typing():
|
||||||
new_user_input_ids = tokenizer.encode(user_message + tokenizer.eos_token, return_tensors='pt')
|
await message.channel.send(cartman_speak(user_message))
|
||||||
bot_output = new_user_input_ids
|
|
||||||
bot_input_ids = torch.cat([new_user_input_ids, bot_output])
|
|
||||||
bot_output = model.generate(
|
|
||||||
bot_input_ids, max_length= 200,
|
|
||||||
pad_token_id=tokenizer.eos_token_id,
|
|
||||||
no_repeat_ngram_size=3,
|
|
||||||
do_sample=True,
|
|
||||||
top_k=100,
|
|
||||||
top_p=0.7,
|
|
||||||
temperature=.8
|
|
||||||
)
|
|
||||||
await message.channel.send('{}'.format(tokenizer.decode(bot_output[:,bot_input_ids.shape[-1]:][0], skip_special_tokens=True)))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.channel.name == 'shitposting':
|
if message.channel.name == 'shitposting':
|
||||||
if user_message.lower().count('musk') > 0:
|
if user_message.lower().count('musk') > 0:
|
||||||
await message.channel.send(user_tweet('elonmusk'))
|
await message.channel.send(user_tweet(44196397))
|
||||||
return
|
return
|
||||||
|
|
||||||
elif user_message.lower() == 'lulzbot' or user_message == 'ligmabot' or user_message == 'L1gMaB0t' or user_message == 'help':
|
elif user_message.lower() == 'lulzbot' or user_message == 'ligmabot' or user_message == 'L1gMaB0t' or user_message == 'help':
|
||||||
|
|
Loading…
Add table
Reference in a new issue