<commit_before>﻿using System.Threading.Tasks;
using Discord.WebSocket;
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Discord;
using Newtonsoft.Json;

namespace Streams
{
    internal class Bot
    {
        private static readonly RequestOptions reqOpt = new RequestOptions()
        {
            RetryMode = RetryMode.RetryRatelimit
        };
        private static readonly EmbedFooterBuilder footer = new EmbedFooterBuilder()
        {
            Text = "service by 3v.fi/l/streams"
        };

        private DiscordSocketClient client = new DiscordSocketClient();
        private Http.Requester request = new Http.Requester(new Uri("https://api.twitch.tv/v5/"));
        private CancellationTokenSource stopswitch = new CancellationTokenSource();
        private Timer streamlooker;
        private ConcurrentDictionary<SocketTextChannel, List<Http.Models.Twitch.User>> streamChannels = new ConcurrentDictionary<SocketTextChannel, List<Http.Models.Twitch.User>>();
        private ConcurrentDictionary<string, IUserMessage> storedMessages = new ConcurrentDictionary<string, IUserMessage>();

        public Bot()
        {

        }

        public async Task Run(string token)
        {
            client.Connected += Client_Connected;
            client.MessageReceived += Client_MessageReceived;
            client.GuildAvailable += Client_GuildAvailable;
            client.Log += msg => Task.Run(() => Console.WriteLine($"Discord.Net log: {msg}"));

            Console.WriteLine($"Connecting using token \"{token}\"");
            await client.LoginAsync(TokenType.Bot, token, true);
            await client.StartAsync();

            Console.WriteLine("Starting update loop");
            streamlooker = new Timer(UpdateStreams, null, 1000, 600000);

            try
            {
                await Task.Delay(-1, stopswitch.Token);
            }
            catch (TaskCanceledException) { /* expected when closing down program via ^C */ }
        }

        private Task Client_GuildAvailable(SocketGuild arg) => Task.Run(() =>
        {
            // Load channel data
            foreach (var channel in arg.TextChannels)
            {
                string channelPath = $"data/{channel.Id}.dat";
                if (File.Exists(channelPath))
                {
                    streamChannels[channel] = JsonConvert.DeserializeObject<List<Http.Models.Twitch.User>>(File.ReadAllText(channelPath));
                }
            }
        });<commit_msg>reduce update interval to 5 min<commit_after>﻿using System.Threading.Tasks;
using Discord.WebSocket;
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Discord;
using Newtonsoft.Json;

namespace Streams
{
    internal class Bot
    {
        private static readonly RequestOptions reqOpt = new RequestOptions()
        {
            RetryMode = RetryMode.RetryRatelimit
        };
        private static readonly EmbedFooterBuilder footer = new EmbedFooterBuilder()
        {
            Text = "service by 3v.fi/l/streams"
        };

        private DiscordSocketClient client = new DiscordSocketClient();
        private Http.Requester request = new Http.Requester(new Uri("https://api.twitch.tv/v5/"));
        private CancellationTokenSource stopswitch = new CancellationTokenSource();
        private Timer streamlooker;
        private ConcurrentDictionary<SocketTextChannel, List<Http.Models.Twitch.User>> streamChannels = new ConcurrentDictionary<SocketTextChannel, List<Http.Models.Twitch.User>>();
        private ConcurrentDictionary<string, IUserMessage> storedMessages = new ConcurrentDictionary<string, IUserMessage>();

        public Bot()
        {

        }

        public async Task Run(string token)
        {
            client.Connected += Client_Connected;
            client.MessageReceived += Client_MessageReceived;
            client.GuildAvailable += Client_GuildAvailable;
            client.Log += msg => Task.Run(() => Console.WriteLine($"Discord.Net log: {msg}"));

            Console.WriteLine($"Connecting using token \"{token}\"");
            await client.LoginAsync(TokenType.Bot, token, true);
            await client.StartAsync();

            Console.WriteLine("Starting update loop");
            streamlooker = new Timer(UpdateStreams, null, 1000, 300000);

            try
            {
                await Task.Delay(-1, stopswitch.Token);
            }
            catch (TaskCanceledException) { /* expected when closing down program via ^C */ }
        }

        private Task Client_GuildAvailable(SocketGuild arg) => Task.Run(() =>
        {
            // Load channel data
            foreach (var channel in arg.TextChannels)
            {
                string channelPath = $"data/{channel.Id}.dat";
                if (File.Exists(channelPath))
                {
                    streamChannels[channel] = JsonConvert.DeserializeObject<List<Http.Models.Twitch.User>>(File.ReadAllText(channelPath));
                }
            }
        });
{'fraction_non_alphanumeric': 0.09849942285494422, 'fraction_numerical': 0.005194305502116198, 'mean_word_length': 2.384765625, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '293838', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1311, 'n_words': 303}