main.py 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import discord
  2. from discord.ext import commands
  3. import asyncio
  4. import server.server as server
  5. import settings
  6. import json
  7. #Request types
  8. import requests
  9. description = """
  10. Discord-SARP Connector\n
  11. Author: dy1zan
  12. """
  13. bot = commands.Bot(command_prefix='!', description=description)
  14. s = None
  15. @bot.event
  16. async def on_ready():
  17. print('Connected to Discord')
  18. global s
  19. s = server.AServer(settings.SERVER_PORT, bot)
  20. s.start()
  21. #These need moving to their own files where Discord commands are specified.
  22. @bot.command(pass_context=True)
  23. async def a(ctx, *, msg : str):
  24. out = json.dumps({
  25. "type":"asay",
  26. "sender":str(ctx.message.author),
  27. "message":msg
  28. })
  29. global s
  30. await s.write(out)
  31. @bot.command(pass_context=True)
  32. async def admins(ctx):
  33. channel = ctx.message.channel
  34. out = json.dumps({
  35. "type":"admins",
  36. "channel":str(channel.id)
  37. })
  38. global s
  39. await s.write(out)
  40. bot.run(settings.BOT_TOKEN)