Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.57 KB | None | 0 0
  1. #CLIENT ID = 580839584422690827
  2. import discord
  3. import wikipedia
  4. import random
  5. import requests
  6. import time
  7. import tensorflow as tf
  8. import numpy as np
  9. start = time.time()
  10. EMBEDDING_DIM = 512
  11.  
  12. def lstm_model(seq_len=150, batch_size=None, stateful=True):
  13.   source = tf.keras.Input(
  14.       name='seed', shape=(seq_len,), batch_size=batch_size, dtype=tf.int32)
  15.  
  16.   embedding = tf.keras.layers.Embedding(input_dim=256, output_dim=EMBEDDING_DIM)(source)
  17.   lstm_1 = tf.keras.layers.LSTM(EMBEDDING_DIM, stateful=stateful, return_sequences=True)(embedding)
  18.   lstm_2 = tf.keras.layers.LSTM(EMBEDDING_DIM, stateful=stateful, return_sequences=True)(lstm_1)
  19.   predicted_char = tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(256, activation='softmax'))(lstm_2)
  20.   model = tf.keras.Model(inputs=[source], outputs=[predicted_char])
  21.   model.compile(
  22.       optimizer=tf.train.RMSPropOptimizer(learning_rate=0.01),
  23.       loss='sparse_categorical_crossentropy',
  24.       metrics=['sparse_categorical_accuracy'])
  25.   return model
  26. #print(discord.__version__)  # check to make sure at least once you're on the right version!
  27. token = replace this
  28.  
  29. client = discord.Client()  # starts the discord client.
  30. loop = False
  31.  
  32. @client.event  # event decorator/wrapper. More on decorators here: https://pythonprogramming.net/decorators-intermediate-python-tutorial/
  33. async def on_ready():  # method expected by client. This runs once when connected
  34.     print(f'We have logged in as {client.user}')  # notification of login.
  35.  
  36.  
  37. @client.event
  38. async def on_message(message):  # event that happens per any message.
  39.     print(f"{message.channel}: {message.author}: {message.author.name}: {message.content}")
  40.     if "!wiki" in message.content.lower():
  41.         await message.channel.send('Alright, you searched wikipedia for' + message.content.replace("!wiki", ""))
  42.         try:
  43.             sumy = wikipedia.summary(message.content.replace("!wiki", ""))
  44.             await message.channel.send(sumy)
  45.         except Exception as e:
  46.             await message.channel.send("No article found")
  47.     elif "!randnum" in message.content.lower():
  48.         msg = message.content.lower()
  49.         parsed_msg = msg.replace("!randnum", "")
  50.         await message.channel.send("Random number generating between: " + parsed_msg)
  51.         randnum = random.randint(*[int(number) for number in parsed_msg.split('-')])
  52.         await message.channel.send(randnum)
  53.     elif "!addme" in message.content.lower():
  54.         await message.channel.send("https://discordapp.com/oauth2/authorize?client_id=580839584422690827&scope=bot&permissions=8")
  55.     elif "!joke" in message.content.lower():
  56.             r = requests.get('https://icanhazdadjoke.com', headers={"Accept":"application/json"})
  57.             raw_joke = r.json()['joke'];
  58.             await message.channel.send(raw_joke)
  59.     elif "!image" in message.content.lower():
  60.         await message.channel.send("https://media.tenor.com/images/1b3aa48cfa63240adfef3a61a179bec0/tenor.gif")
  61.     elif("!trump" in message.content.lower() and time.time()-start < 30): # 30 second guard from spam
  62.         PREDICT_LEN = 280
  63.         prediction_model = lstm_model(seq_len=1, batch_size=BATCH_SIZE, stateful=True)
  64.         prediction_model.load_weights('thedonald.h5')
  65.         seed_txt = message.content.lower()[6:]
  66.         seed = transform(seed_txt)
  67.         seed = np.repeat(np.expand_dims(seed, 0), BATCH_SIZE, axis=0)
  68.         prediction_model.reset_states()
  69.         for i in range(len(seed_txt) - 1):
  70.           prediction_model.predict(seed[:, i:i + 1])
  71.         predictions = [seed[:, -1:]]
  72.         for i in range(PREDICT_LEN):
  73.           last_word = predictions[-1]
  74.           next_probits = prediction_model.predict(last_word)[:, 0, :]
  75.           next_idx = [
  76.               np.random.choice(256, p=next_probits[i])
  77.               for i in range(BATCH_SIZE)
  78.           ]
  79.           predictions.append(np.asarray(next_idx, dtype=np.int32))
  80.         for i in range(BATCH_SIZE):
  81.       p = [predictions[j][i] for j in range(PREDICT_LEN)]
  82.       generated = ''.join([chr(c) for c in p])
  83.       start=time.time()
  84.       await message.channel.send(generated)
  85.       start=time.time()
  86.     if (str(message.author.name) == "Skierman" or str(message.author.name) == "TauPiPhi") and "who am i" in message.content.lower():
  87.         await message.channel.send('The most amazing person ever!!!')
  88.     if("Watch your profanity." in message.content.lower() and loop < 10):
  89.         loop +=1
  90.         await message.channel.send("Watch your fucking profanity.")
  91.     elif(loop>=10):
  92.         loop = 0
  93.  
  94.  
  95. client.run(token)  # recall my token was saved!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement