Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import discord
  2. from discord.ext.commands import Bot
  3. from discord.ext import commands
  4. import asyncio
  5. import random
  6. import mysql.connector
  7. import sys
  8. from blinker import signal
  9. import zmq
  10.  
  11. #Variable pour connexion à la base T4C
  12. mysql_host = "localhost"
  13. mysql_user = "root"
  14. mysql_password = ""
  15. mysql_base = ""
  16.  
  17. #Variable pour le bot Discord
  18. botKey = "myKey"
  19.  
  20. description = '''A bot form T4C'''
  21. client = commands.Bot(command_prefix="?", description=description)
  22.    
  23. context = zmq.Context()
  24. socket = context.socket(zmq.REP)
  25. socket.bind("tcp://*:5555")
  26.    
  27. @client.event
  28. @asyncio.coroutine
  29. def on_ready():
  30.     print('Logged in as')
  31.     print(client.user.name)
  32.     print(client.user.id)
  33.     print('------')
  34.  
  35. # Commande cimetiere, annonce le top 10 XP
  36. @client.command()
  37. @asyncio.coroutine
  38. def startRoutine():
  39.     #  Wait for next request from client
  40.     print("Waiting request...")
  41.     message = socket.recv()
  42.     client.say('%s' % message)
  43.     socket.send(b"World")
  44.     print("Received request: %s" % message)
  45.    
  46. # Commande cimetiere, annonce le top 10 XP
  47. @client.command()
  48. @asyncio.coroutine
  49. def top10XP():
  50.     print('TOP 10 REQUEST')
  51.     conn = mysql.connector.connect(host=mysql_host,user=mysql_user,password=mysql_password, database=mysql_base)
  52.     cursor = conn.cursor()
  53.     cursor.execute("""SELECT PlayerName,CurrentLevel FROM playingcharacters ORDER BY CurrentLevel DESC LIMIT 10""")
  54.     rows = cursor.fetchall()
  55.     for row in rows:
  56.             yield from  client.say('{0} - lvl {1}'.format(row[0],row[1]))
  57.     conn.close()
  58.  
  59. client.run(botKey)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement