예제 #1
0
        public async Task InitializeAsync(CancellationToken ct)
        {
            var serviceConfig = await ResourceResolver.LoadConfigurationAsync <DiscordGatewayService, DiscordServiceConfiguration>();

            var clientConfig = new DiscordSocketConfig
            {
                AlwaysDownloadUsers = true,
                GuildSubscriptions  = true,
            };

            Client = new DiscordSocketClient(clientConfig);

            // Client.Log += msg =>
            // {
            //     Console.WriteLine(msg.Message);
            //     return Task.CompletedTask;
            // };

            Client.MessageReceived += _HandleMessageReceived;
            Client.Disconnected    += ex =>
            {
                _MessageChannel.Writer.Complete(ex);
                return(Task.CompletedTask);
            };

            await Client.LoginAsync(TokenType.Bot, serviceConfig.OAuthToken);

            // would be cool if we could use a custom status here that was not a game but it seems
            // the discord API does not properly support this yet and the library subsequently also
            await Client.SetGameAsync("with Electric Sheep"); // *Playing* with Electric Sheep

            await Client.StartAsync();
        }
예제 #2
0
        public async Task InitializeAsync(CancellationToken ct)
        {
            var serviceConfig = await ResourceResolver.LoadConfigurationAsync <TwitchGatewayService, TwitchServiceConfiguration>();

            _Connection         = new TcpClient();
            _Connection.NoDelay = true;

            Console.WriteLine("Connecting to Twitch IRC gateway");
            await _Connection.ConnectAsync("irc.chat.twitch.tv", 6667, ct);

            _ConnectionReader           = new StreamReader(_Connection.GetStream());
            _ConnectionWriter           = new StreamWriter(_Connection.GetStream());
            _ConnectionWriter.AutoFlush = true;

            await _ConnectionWriter.WriteLineAsync($"PASS {serviceConfig.OAuthToken}".AsMemory(), ct);

            await _ConnectionWriter.WriteLineAsync($"NICK {serviceConfig.Username}".AsMemory(), ct);

            // TODO: create read function that utilizes cancellation token
            var responseLine = await _ConnectionReader.ReadLineAsync();

            var responseLineParts = responseLine.Split(null, 3);

            if (responseLineParts.Length < 3 || responseLineParts[1] != "001")
            {
                throw new Exception("Twitch IRC authentication failed");
            }

            Console.WriteLine("Twitch IRC connection authenticated");

            // this twitch capability gives us user member information they dont send by default.
            // there are other capabilities including ones that let us see users preferred display names
            // and chat color but this is not supported at this time
            await _ConnectionWriter.WriteLineAsync("CAP REQ :twitch.tv/membership".AsMemory(), ct);

            // join channels
            foreach (var channel in serviceConfig.Channels)
            {
                await _ConnectionWriter.WriteLineAsync($"JOIN #{channel}".AsMemory(), ct);
            }
        }
예제 #3
0
 public async Task InitializeAsync(CancellationToken ct)
 {
     config = await ResourceResolver.LoadConfigurationAsync <Gun, GunConfiguration>();
 }