<commit_before>""" Twitch notifier template

Commands:
!twitch
"""

import logging

import discord
import asyncio
import requests

from pcbot import Config

commands = {
    "twitch": {
        "usage": "!twitch <option>\n"
                 "Options:\n"
                 "    set <username>\n"
                 "    get\n"
                 "    notify-channel [channel]",
        "desc": "Handle twitch commands.\n"
                "`set` assigns your twitch account for notifying.\n"
                "`get` returns your assigned twitch username.\n"
                "~~`notify-channel` sets a channel as the notify channel. This channel should not be used by any "
                "member. Specify no channel to disable. **Requires `Manage Server` permission.**~~"
    }
}

twitch_channels = Config("twitch-channels", data={"channels": {}})
live_channels = {}
update_interval = 60  # Seconds

twitch_api = "https://api.twitch.tv/kraken"

logging.getLogger("requests").setLevel(logging.WARNING)


@asyncio.coroutine
def on_ready(client: discord.Client):
    while True:
        yield from asyncio.sleep(update_interval)

        # Go through all set channels and update their status
        for member_id, channel in twitch_channels.data["channels"].items():
            request = requests.get(twitch_api + "/streams/" + channel)
            stream = request.json().get("stream")

            if member_id in live_channels:
                if not stream:
                    live_channels.pop(member_id)

            if stream:
                live_channels[member_id] = stream

                # Tell every mutual channel between the streamer and the bot that streamer started streaming
                for server in client.servers:
                    member = server.get_member(member_id)

                    if member:
                        m = "{0} went live at {1[channel][url]} !\n" \
                            "**{1[channel][display_name]}**: {1[channel][status]}\n" \
                            "*Playing {1[game]}*\n" \
                            "{1[preview][large]}".format(member.mention, stream)
                        yield from client.send_message(server, m)


@asyncio.coroutine
def on_message(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!twitch":<commit_msg>Only post stream status once<commit_after>""" Twitch notifier template

Commands:
!twitch
"""

import logging

import discord
import asyncio
import requests

from pcbot import Config

commands = {
    "twitch": {
        "usage": "!twitch <option>\n"
                 "Options:\n"
                 "    set <username>\n"
                 "    get\n"
                 "    notify-channel [channel]",
        "desc": "Handle twitch commands.\n"
                "`set` assigns your twitch account for notifying.\n"
                "`get` returns your assigned twitch username.\n"
                "~~`notify-channel` sets a channel as the notify channel. This channel should not be used by any "
                "member. Specify no channel to disable. **Requires `Manage Server` permission.**~~"
    }
}

twitch_channels = Config("twitch-channels", data={"channels": {}})
live_channels = {}
update_interval = 60  # Seconds

twitch_api = "https://api.twitch.tv/kraken"

logging.getLogger("requests").setLevel(logging.WARNING)


@asyncio.coroutine
def on_ready(client: discord.Client):
    while True:
        yield from asyncio.sleep(update_interval)

        # Go through all set channels and update their status
        for member_id, channel in twitch_channels.data["channels"].items():
            request = requests.get(twitch_api + "/streams/" + channel)
            stream = request.json().get("stream")

            if member_id in live_channels:
                if not stream:
                    live_channels.pop(member_id)
            else:
                if stream:
                    live_channels[member_id] = stream

                    # Tell every mutual channel between the streamer and the bot that streamer started streaming
                    for server in client.servers:
                        member = server.get_member(member_id)

                        if member:
                            m = "{0} went live at {1[channel][url]} !\n" \
                                "**{1[channel][display_name]}**: {1[channel][status]}\n" \
                                "*Playing {1[game]}*\n" \
                                "{1[preview][large]}".format(member.mention, stream)
                            yield from client.send_message(server, m)


@asyncio.coroutine
def on_message(client: discord.Client, message: discord.Message, args: list):
    if args[0] == "!twitch":
{'fraction_non_alphanumeric': 0.11212378126324714, 'fraction_numerical': 0.0038151759220008477, 'mean_word_length': 1.9438552713661883, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6841178', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1248, 'n_words': 350}