Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #CLIENT ID = 580839584422690827
- import discord
- import wikipedia
- import random
- import requests
- import time
- import tensorflow as tf
- import numpy as np
- start = time.time()
- EMBEDDING_DIM = 512
- def lstm_model(seq_len=150, batch_size=None, stateful=True):
- source = tf.keras.Input(
- name='seed', shape=(seq_len,), batch_size=batch_size, dtype=tf.int32)
- embedding = tf.keras.layers.Embedding(input_dim=256, output_dim=EMBEDDING_DIM)(source)
- lstm_1 = tf.keras.layers.LSTM(EMBEDDING_DIM, stateful=stateful, return_sequences=True)(embedding)
- lstm_2 = tf.keras.layers.LSTM(EMBEDDING_DIM, stateful=stateful, return_sequences=True)(lstm_1)
- predicted_char = tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(256, activation='softmax'))(lstm_2)
- model = tf.keras.Model(inputs=[source], outputs=[predicted_char])
- model.compile(
- optimizer=tf.train.RMSPropOptimizer(learning_rate=0.01),
- loss='sparse_categorical_crossentropy',
- metrics=['sparse_categorical_accuracy'])
- return model
- #print(discord.__version__) # check to make sure at least once you're on the right version!
- token = replace this
- client = discord.Client() # starts the discord client.
- loop = False
- @client.event # event decorator/wrapper. More on decorators here: https://pythonprogramming.net/decorators-intermediate-python-tutorial/
- async def on_ready(): # method expected by client. This runs once when connected
- print(f'We have logged in as {client.user}') # notification of login.
- @client.event
- async def on_message(message): # event that happens per any message.
- print(f"{message.channel}: {message.author}: {message.author.name}: {message.content}")
- if "!wiki" in message.content.lower():
- await message.channel.send('Alright, you searched wikipedia for' + message.content.replace("!wiki", ""))
- try:
- sumy = wikipedia.summary(message.content.replace("!wiki", ""))
- await message.channel.send(sumy)
- except Exception as e:
- await message.channel.send("No article found")
- elif "!randnum" in message.content.lower():
- msg = message.content.lower()
- parsed_msg = msg.replace("!randnum", "")
- await message.channel.send("Random number generating between: " + parsed_msg)
- randnum = random.randint(*[int(number) for number in parsed_msg.split('-')])
- await message.channel.send(randnum)
- elif "!addme" in message.content.lower():
- await message.channel.send("https://discordapp.com/oauth2/authorize?client_id=580839584422690827&scope=bot&permissions=8")
- elif "!joke" in message.content.lower():
- r = requests.get('https://icanhazdadjoke.com', headers={"Accept":"application/json"})
- raw_joke = r.json()['joke'];
- await message.channel.send(raw_joke)
- elif "!image" in message.content.lower():
- await message.channel.send("https://media.tenor.com/images/1b3aa48cfa63240adfef3a61a179bec0/tenor.gif")
- elif("!trump" in message.content.lower() and time.time()-start < 30): # 30 second guard from spam
- PREDICT_LEN = 280
- prediction_model = lstm_model(seq_len=1, batch_size=BATCH_SIZE, stateful=True)
- prediction_model.load_weights('thedonald.h5')
- seed_txt = message.content.lower()[6:]
- seed = transform(seed_txt)
- seed = np.repeat(np.expand_dims(seed, 0), BATCH_SIZE, axis=0)
- prediction_model.reset_states()
- for i in range(len(seed_txt) - 1):
- prediction_model.predict(seed[:, i:i + 1])
- predictions = [seed[:, -1:]]
- for i in range(PREDICT_LEN):
- last_word = predictions[-1]
- next_probits = prediction_model.predict(last_word)[:, 0, :]
- next_idx = [
- np.random.choice(256, p=next_probits[i])
- for i in range(BATCH_SIZE)
- ]
- predictions.append(np.asarray(next_idx, dtype=np.int32))
- for i in range(BATCH_SIZE):
- p = [predictions[j][i] for j in range(PREDICT_LEN)]
- generated = ''.join([chr(c) for c in p])
- start=time.time()
- await message.channel.send(generated)
- start=time.time()
- if (str(message.author.name) == "Skierman" or str(message.author.name) == "TauPiPhi") and "who am i" in message.content.lower():
- await message.channel.send('The most amazing person ever!!!')
- if("Watch your profanity." in message.content.lower() and loop < 10):
- loop +=1
- await message.channel.send("Watch your fucking profanity.")
- elif(loop>=10):
- loop = 0
- client.run(token) # recall my token was saved!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement