Exemplo n.º 1
0
        // MessageOwnerAsync
        //
        // Parameters:
        // msg (SocketUserMessage)
        // reason (Optional : String)

        #region MessageOwnerAsync
        public async Task MessageOwnerAsync(SocketUserMessage msg, string reason = "Unknown")
        {
            // Create the DMChannel object to send message to owner
            var dmchannel = await _discord.GetDMChannelAsync(dm_channel_id);

            if (dmchannel == null)
            {
                await Console.Out.WriteLineAsync("[DM CHANNEL] Do Not Forget - DM the bot to create the error reporting DM channel.");

                return;
            }
            StringBuilder sb = new StringBuilder();

            string cmd = msg.Content.Remove(0, 1);

            if (cmd.Contains(" "))
            {
                cmd = cmd.Split("0")[0];
            }

            sb.Append($"{DateTime.UtcNow.ToString("hh:mm:ss")} [{cmd}]: Failed to execute - ");

            sb.Append(reason.Equals("Unknown") ? "No reason specified." : $"Reason: {reason}");

            await dmchannel.SendMessageAsync(sb.ToString());
        }
        private async Task AskToRelogin(string discordId)
        {
            _logger.LogInformation("Sending refresh notification");
            var channel = await _discordSocketClient.GetDMChannelAsync(ulong.Parse(discordId));

            await channel.SendMessageAsync(
                $"Hey, I failed refreshing access to your Strava account. Please use `join` command again in the server of leaderboard.");
        }
Exemplo n.º 3
0
        public override IList <Response> Execute(SenderSettings senderDetail, IMessageDetail args)
        {
            ServerSettings       serverSettings = senderDetail.ServerSettings;
            CommandMessageHelper command        = new CommandMessageHelper(serverSettings.CommandSymbol, args.Message);
            string requestStr = command.CommandDetail;
            ulong  requestedId;

            if (string.IsNullOrWhiteSpace(requestStr))
            {
                // Default to the user asking.
                requestedId = args.UserId;
            }
            else
            {
                // Parse a mention?
                if (requestStr.StartsWith("<@") && requestStr.EndsWith(">"))
                {
                    requestStr = requestStr.Substring("<@".Length, requestStr.Length - 3); // Minus 3 for <@nnnnn>
                }

                // Id?
                if (!ulong.TryParse(requestStr, out requestedId))
                {
                    // No, fail.
                    return(Response.CreateArrayFromString($"{Emojis.CrossSymbol} {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "Error_NoResults")}: {requestStr}"));
                }
            }

            if (client != null)
            {
                Task.Run(async() =>
                {
                    // From the id, determine if it's a user or server.
                    // Is it a server?
                    var candidateServer = await client.GetGuildAsync(requestedId).ConfigureAwait(false);
                    if (candidateServer != null)
                    {
                        await asyncResponder.SendResponseAsync(args, Response.CreateFromString($"{candidateServer.IconUrl}")).ConfigureAwait(false);
                    }

                    // Is it a channel?
                    IChannel candidateChannel = await client.GetDMChannelAsync(requestedId).ConfigureAwait(false);
                    if (candidateChannel != null)
                    {
                        await asyncResponder.SendResponseAsync(args, Response.CreateFromString($"{candidateChannel.GetGuild().IconUrl}")).ConfigureAwait(false);
                    }

                    // Is it a user?
                    IUser candidateUser = client.GetUser(requestedId);
                    if (candidateUser != null)
                    {
                        await asyncResponder.SendResponseAsync(args, Response.CreateFromString($"{candidateUser.GetAvatarUrl(ImageFormat.Auto, 2048)}")).ConfigureAwait(false);
                    }
                });
            }
            return(new Response[] { Response.WaitForAsync });
        }
Exemplo n.º 4
0
        private async Task RefreshChatsApi(bool postMessage)
        {
            try
            {
                if (_client.Guilds.Any())
                {
                    try
                    {
                        _latestPromo = await GetChatsFromUrl(ApiCallUrl, 0).ConfigureAwait(false);

                        var numberOfResults = _latestPromo.NumberOfPageResults;

                        Result stream = _latestPromo.Results.FirstOrDefault(x => !IgnoreList.Contains(x.ChannelName));
                        lastResult = stream;
                        if (_wasStreamRunning == false && numberOfResults != 0 && stream != null)
                        {
                            await UpdateTask(stream, postMessage).ConfigureAwait(false);

                            await Subscribe.PostLivestream(stream, _client).ConfigureAwait(false);

                            _wasStreamRunning = true;
                        }
                        else if (_wasStreamRunning && (numberOfResults == 0 || stream == null))
                        {
                            await UpdateTask(stream, postMessage).ConfigureAwait(false);

                            _wasStreamRunning = false;
                        }
                    }
                    catch (TimeoutException)
                    {
                        Console.WriteLine("LivestreamChecker timed out.");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"LivestreamChecker sucks: {ex} \n {ex.Message}");
                var ownerDmChannel = await _client.GetDMChannelAsync(85817630560108544).ConfigureAwait(false);

                if (ownerDmChannel != null)
                {
                    await ownerDmChannel.SendMessageAsync($"LivestreamChecker threw an {ex.GetType()}, check the logs").ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 5
0
        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            var guilds = _client.Guilds.Select(x => new GuildChannelList
            {
                Channel = x.Channels.FirstOrDefault(y => y.Name.ToLower().Contains("test")),
                Guild   = x,
            }).Where(x => x.Channel != null).ToList();

            foreach (var guild in guilds)
            {
                if (guild.Channel.Users != null)
                {
                    foreach (var user in guild.Channel.Users)
                    {
                        if (!idList.Any(x => x.Guild.Id == guild.Guild.Id && x.Id == user.Id))
                        {
                            var added = new GuildPassedTestList
                            {
                                Guild = guild.Guild,
                                Id    = user.Id,
                            }; idList.Add(added);

                            var random = new Random();
                            var n1     = random.Next(2, 11);
                            var n2     = random.Next(2, 11);
                            var result = n1 * n2;
                            Console.WriteLine($"{guild.Guild.Name} {user.Username}/{user.Mention} joining test, question: {n1} * {n2} = {result}");
                            var msg  = user.SendMessageAsync($"{n1} * {n2} = ?");
                            var rmsg = user.SendMessageAsync($"you have 5 secs.");
                            rmsg.Wait();
                            msg.Wait();
                            Task.Delay(5000).Wait();
                            try
                            {
                                var dmch = user.GetOrCreateDMChannelAsync().Result.Id;
                                var dm   = _client.GetDMChannelAsync(dmch).Result.GetMessagesAsync(1).ToListAsync();
                                dm.AsTask().Wait();
                                var cdm  = dm.Result[1];
                                var msgx = cdm.First().Content != null?cdm.First().Content : "";

                                if (msgx != null && result.ToString() != msgx)
                                {
                                    Console.WriteLine($"{guild.Guild.Name} {user.Username}/{user.Mention} fuckedup");
                                    user.SendMessageAsync("time is up.");
                                    user.ModifyAsync(x => x.Channel = null);
                                    idList.Remove(added);
                                }
                                else
                                {
                                    Console.WriteLine($"{guild.Guild.Name} {user.Username}/{user.Mention} passed the test!");
                                    user.SendMessageAsync("passed the test nice!");
                                }
                            }
                            catch (Exception ex)
                            {
                                idList.Remove(added);
                                Console.WriteLine($"{guild.Guild.Name} {user.Username}/{user.Mention} code was broken!");
                            }
                        }
                    }
                }
            }

            var anyKick = AnyKick();

            if (anyKick != null)
            {
                Console.WriteLine($"Using disconnect-kick perm: {anyKick} {DateTime.Now.ToString()}");
            }
        }