Last active
May 29, 2017 03:16
-
-
Save Atomicbeast101/751ea7db39ac7339e42dc48746832eea to your computer and use it in GitHub Desktop.
Task Error - Discord Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| from configparser import ConfigParser | |
| import discord | |
| from twitch.api import v3 | |
| # Preparing the bot | |
| dclient = discord.Client() | |
| # Twitch setup | |
| twitch_enabled = config.getboolean('Twitch', 'Enabled') | |
| streamers = config.get('Twitch', 'Users').split(',') | |
| active = list() | |
| start_time = 0 | |
| async def twitch_live_stream_notify(): | |
| await dclient.wait_until_ready() | |
| while not dclient.is_closed: | |
| await asyncio.sleep(config.getint('Twitch', 'Interval')) | |
| if twitch_enabled and len(streamers) > 0: | |
| for streamer in streamers: | |
| stream = v3.streams.by_channel(streamer) | |
| if stream['stream'] is not None: | |
| if streamer not in active: | |
| await dclient.send_message(dclient.get_channel(str(twitch_channel)), | |
| "**{0}** is now live! @<https://www.twitch.tv/{0}>".format(streamer)) | |
| log('TWITCH', 'Announced that player {} is streaming on Twitch.'.format(streamer)) | |
| active.append(streamer) | |
| else: | |
| if streamer in active: | |
| active.remove(streamer) | |
| # Execute Twitch Loop | |
| if twitch_enabled: | |
| dclient.loop.create_task(twitch_live_stream_notify()) | |
| # Activate Bot | |
| dclient.run(Token_ID) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment