Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- import random
- import pandas as pd
- import numpy as np
- import discord
- import asyncio
- import configparser
- from sqlalchemy import create_engine
- import MySQLdb
- import sqlite3
- config = configparser.ConfigParser()
- config.read("F:/Pythonki/etc/config.txt")
- password = config.get("config","password")
- username = config.get("config","user")
- port = config.get("config","port")
- host = config.get("config","host")
- engine = create_engine('mysql+mysqldb://'+username+':'+password+'@'+host+':'+port+'/test', echo = False)
- dbLen = pd.read_sql('SELECT * FROM memes ORDER BY ID DESC LIMIT 1', con=engine)['ID'].values[0]
- TOKEN = 'NjMyOTg4Mjc2MDU5NDA2NDE1.XaNotg.jKbp9OZWHbQrocLtK5hUx0DItvA'
- client = discord.Client()
- @client.event
- async def on_message(message):
- if message.author == client.user:
- return
- @client.event
- async def on_reaction_add(reaction, user):
- await message.channel.send('Thank you for reacting, {0.author.mention}!'.format(message))
- def randomize_meme():
- i = random.randrange(0,dbLen)
- meme = pd.read_sql("SELECT * FROM memes WHERE ID ="+str(i), con=engine)
- return meme['url'].values[0]
- if message.content.startswith('!facts'):
- if len(message.content.split()) < 2:
- msg_user = 'Please add one of the following persons: piotr/natalka/pawel.'
- elif message.content.split()[1] == 'piotr':
- msg_user = 'To my best knowledge, Piotr is a smol aplo.'
- elif message.content.split()[1] == 'natalka':
- msg_user = 'As far as my knowledge goes, this user is an ordinary duck.'
- elif message.content.split()[1] == 'pawel':
- msg_user = "From what I heard, this user doesn't listen to hip-hop."
- else:
- msg_user = 'Currently, I posses information about pawel, natalka and piotr only.'
- await message.channel.send(msg_user)
- if message.content.startswith('!meme'):
- msg = ('I live to bring you the freshest memes \n ' + randomize_meme()).format(message)
- await message.channel.send(msg)
- if message.content.startswith('?meme'):
- msg = 'Yes, that is right - currently there are ' + str(dbLen) + ' memes in my database. Type !meme to generate a random meme.'.format(message)
- await message.channel.send(msg)
- if message.content.startswith('!hello'):
- hello = 'Hello, {0.author.mention}'.format(message)
- await message.channel.send(hello)
- @client.event
- async def on_ready():
- print('Logged in as')
- print(client.user.name)
- print(client.user.id)
- print('------')
- client.run(TOKEN)
- if __name__== "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement