So I'm making a Discord Bot that posts when a person goes live on Twitch.tv. At the moment I have a Python program that runs the bot and a program that runs a mini server to receive the data from the Twitch server(webhook). I am unsure on how to pass on the data I receive from my server to the discord bot. Both programs have to be running at the same time.
DiscordBot
import discord
client = discord.Client()
async def goes_live(data):
print(data)
print('Going Live')
msg = '--- has gone live'
await client.send_message(discord.Object(id='---'), msg)
@client.event
async def on_message(message):
if message.author == client.user:
return
message.content = message.content.casefold()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run('---')
Web server
import web
urls = ('/.*', 'hooks')
app = web.application(urls, globals())
class hooks:
def POST(self):
data = web.data()
print("")
print('DATA RECEIVED:')
print(data)
print("")
return 'OK'
def GET(self):
try:
data = web.input()
data = data['hub.challenge']
print("Hub challenge: ", data)
return data
except KeyError:
return web.BadRequest
if __name__ == '__main__':
app.run()
asyncio
, so that's probably a good place to start looking. – Subdued