Esempio n. 1
0
        private async Task WelcomeChannelSetup(SocketCommandContext context)
        {
            var tmpMessage = await context.Channel.SendMessageAsync(embed : CustomFormats.CreateBasicEmbed(
                                                                        "Welcome Channel Setup",
                                                                        "Cobra will send messages to this channel when someone joins/leaves the server.\n" +
                                                                        "Please mention the #textChannel you want to setup as the Welcome Channel.\n" +
                                                                        "Type `reset` to reset the Welcome Channel thus disabling this functionality.",
                                                                        Color.Blue));

            var nextMessageResult = await _interactivityService.NextMessageAsync(x => x.Author == context.User);

            if (nextMessageResult.IsSuccess)
            {
                var msgContent = nextMessageResult.Value.Content;

                if (msgContent == "reset")
                {
                    await ChangeWelcomeChannel(context);

                    await context.Channel.SendMessageAsync(embed : CustomFormats.CreateBasicEmbed(
                                                               "Welcome channel changed",
                                                               "Welcome channel was reset.\nYour server doesn't have a welcome channel setup right now.",
                                                               Color.DarkMagenta));
                }
                else
                {
                    if (nextMessageResult.Value.MentionedChannels.Any())
                    {
                        if (nextMessageResult.Value.MentionedChannels.First() is ITextChannel textChannel)
                        {
                            await ChangeWelcomeChannel(context, textChannel);

                            await context.Channel.SendMessageAsync(embed : CustomFormats.CreateBasicEmbed(
                                                                       "Welcome channel changed",
                                                                       $"Welcome channel is now {textChannel.Mention}", 0x268618));
                        }
                        else
                        {
                            await context.Channel.SendMessageAsync(
                                embed : CustomFormats.CreateErrorEmbed("Invalid text channel!"));
                        }
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync(
                            embed : CustomFormats.CreateErrorEmbed("No text channels mentioned!"));
                    }
                }

                await nextMessageResult.Value.DeleteAsync();

                await tmpMessage.DeleteAsync();
            }
        }
Esempio n. 2
0
        public async Task EditNoteAsync(string groupName, string noteName)
        {
            var note = await _db.GetNoteAsync(groupName, noteName);

            if (note == null)
            {
                await Context.Message.AddReactionAsync(new Emoji("❓"));

                return;
            }

            await ReplyAsync(embed : new EmbedBuilder
            {
                Title       = "Old Message:",
                Description = note.Message
            }.Build());

            await ReplyAsync("Please enter the new message:");

            var result = await _interactivityService.NextMessageAsync(x => x.Author == Context.User);

            if (result?.IsSuccess == true)
            {
                note.Message = result.Value.Content;
                await _db.UpdateNoteAsync(note, Context.User);

                await result.Value.AddReactionAsync(new Emoji("✅"));
            }
        }
Esempio n. 3
0
        public async Task SetModChannel()
        {
            var T      = ReplyAsync($"{prefix}show mod-channel");
            var result = await _interactive.NextMessageAsync((message) =>
            {
                return(message.Author.Id == 428187007965986826 && message.Channel.Id == Context.Channel.Id && message.MentionedChannels.Count == 1);
            }, null, TimeSpan.FromSeconds(10));

            await T;

            if (result.IsSuccess)
            {
                var channel         = result.Value.MentionedChannels.First();
                var currentSettings = _settings[Context.Guild.Id];
                currentSettings.PNavChannel = channel.Id;
                _settings[Context.Guild.Id] = currentSettings;
                await ReplyAsync($"Moderation Channel successfully set to <#{channel.Id}>");
            }
            else
            {
                await ReplyAsync($"Did not receive a Response from PokeNav in time!\nMake sure PokeNav is able to respond in this Channel!");
            }
        }
Esempio n. 4
0
        private async Task Work(ulong guildId, IMessageChannel invokedChannel, CancellationToken token)
        {
            IUserMessage message = null;

            if (progress.ContainsKey(guildId))
            {
                message = progress[guildId];
            }

            if (createQueues.TryGetValue(guildId, out Queue <string> queue))
            {
                if (_settings[guildId].PNavChannel != null)
                {
                    IMessageChannel channel = _client.GetChannel((ulong)_settings[guildId].PNavChannel) as IMessageChannel;

                    if (channel == null)
                    {
                        await _logger.Log(new LogMessage(LogSeverity.Error, nameof(Work), $"Mod-Channel was no Message Channel for Guild {guildId}!"));

                        await invokedChannel.SendMessageAsync($"There was a problem with the mod-channel! try to run `{_settings[guildId].Prefix}set mod-channel` and then `{_settings[guildId].Prefix}resume` to try again!");

                        return;
                    }

                    while (queue.Count > 0)
                    {
                        if (token.IsCancellationRequested)
                        {
                            //workers.Remove(guildId);
                            tokens.Remove(guildId, out CancellationTokenSource s);
                            s.Dispose();
                            token.ThrowIfCancellationRequested();
                        }
                        string      current = queue.Dequeue();
                        IDisposable typing  = null;
                        try
                        {
                            typing = channel.EnterTypingState(typingOptions);
                        }
                        catch (Exception e)
                        {
                            await _logger.Log(new LogMessage(LogSeverity.Error, nameof(Work), $"Error while entering typing state in Guild {guildId}: {e.Message}", e));
                        }
                        Task t = Task.CompletedTask;
                        try
                        {
                            t = channel.SendMessageAsync($"{prefix}{current}", false, null, options);
                        }
                        catch (Exception e)
                        {
                            await _logger.Log(new LogMessage(LogSeverity.Error, nameof(Work), $"Error while sending Create Message in Guild {guildId}: {e.Message}", e));
                        }
                        // wait for PokeNav to respond...
                        var Result = await _inter.NextMessageAsync(x => x.Author.Id == 428187007965986826 && x.Channel.Id == channel.Id && x.Embeds.Count == 1 && (x.Content == "The following poi has been created for use in your community:" || x.Embeds.First().Title == "Error"), null, TimeSpan.FromSeconds(10));

                        await t;
                        if (typing != null)
                        {
                            typing.Dispose();
                        }
                        if (Result.IsSuccess == false)
                        {
                            try
                            {
                                await channel.SendMessageAsync($"PokeNav did not respond in time! Please try again by Hand!", false, null, options);
                            }
                            catch (Exception e)
                            {
                                await _logger.Log(new LogMessage(LogSeverity.Error, nameof(Work), $"Error while sending Error Message in Guild {guildId}: {e.Message}", e));
                            }
                            await _logger.Log(new LogMessage(LogSeverity.Info, nameof(Work), $"PokeNav did not respond within 10 seconds in Guild {guildId}."));
                        }
                        if (message != null && queue.Count % 5 == 0) // do not edit every time because of rate limits
                        {
                            try
                            {
                                await message.ModifyAsync((x) =>
                                {
                                    EmbedBuilder embed = message.Embeds.First().ToEmbedBuilder();
                                    embed.Fields.Find((x) => x.Name == "Creations").Value = queue.Count;
                                    x.Embed = embed.Build();
                                }, options);
                            }
                            catch (Exception e)
                            {
                                await _logger.Log(new LogMessage(LogSeverity.Error, nameof(Work), $"Error while editing progress message in Guild {guildId}: {e.Message}", e));
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        await invokedChannel.SendMessageAsync($"PokeNav Moderation Channel not set yet! Run `{_settings[guildId].Prefix}set mod-channel` to set it, then run `{_settings[guildId].Prefix}resume` to create the PoI!");
                    }
                    catch (Exception e)
                    {
                        await _logger.Log(new LogMessage(LogSeverity.Error, nameof(Work), $"Error while sending error message in Guild {guildId}: {e.Message}", e));
                    }
                    if (message != null)
                    {
                        try
                        {
                            await message.ModifyAsync((x) =>
                            {
                                EmbedBuilder embed = message.Embeds.First().ToEmbedBuilder();
                                embed.Title        = "Paused";
                                x.Embed            = embed.Build();
                            }, options);
                        }
                        catch (Exception e)
                        {
                            await _logger.Log(new LogMessage(LogSeverity.Error, nameof(Work), $"Error while editing progress message in Guild {guildId}: {e.Message}", e));
                        }
                    }
                    await _logger.Log(new LogMessage(LogSeverity.Info, nameof(Work), $"Execution failed in Guild {guildId}: Mod-Channel was not set!"));
                }
            }

            if (editQueues.ContainsKey(guildId) && editQueues[guildId].Any())
            {
                if (message != null)
                {
                    try
                    {
                        await message.ModifyAsync((x) =>
                        {
                            EmbedBuilder embed = message.Embeds.First().ToEmbedBuilder();
                            embed.Fields.Find((x) => x.Name == "Creations").Value = queue.Count;
                            x.Embed = embed.Build();
                        }, options);
                    }
                    catch (Exception e)
                    {
                        await _logger.Log(new LogMessage(LogSeverity.Error, nameof(Work), $"Error while editing progress message in Guild {guildId}: {e.Message}", e));
                    }
                }
                workers[guildId] = Edit(guildId, invokedChannel, token); // proceed with edits after creation is complete if there are any.
            }
            else
            {
                workers.Remove(guildId);
                tokens.Remove(guildId, out CancellationTokenSource source);
                if (message != null)
                {
                    try
                    {
                        await message.DeleteAsync(options);
                    }
                    catch (Exception e)
                    {
                        await _logger.Log(new LogMessage(LogSeverity.Error, nameof(Work), $"Error while deleting progress message in Guild {guildId}: {e.Message}", e));
                    }
                    progress.Remove(guildId);
                }
                source.Dispose();
            }
        }
Esempio n. 5
0
        public async Task SetupGuildConfig()
        {
            var modelResult = await CheckStaffAndRetrieveModel();

            if (modelResult.IsFailure())
            {
                return;
            }
            var model = modelResult.Get();

            _logging.Info($"{Context.User.Username}#{Context.User.Discriminator} in Guild {Context.Guild.Name}({Context.Guild.Id}) calling Setup...");
            await SendChannelMessage(
                $"**Setting up bot...** (Called by {MentionUtils.MentionUser(Context.User.Id)})");
            await SendChannelMessage(
                "**What is the logging channel?**");

            ulong channel = 0;
            var   result  = await _interactivity.NextMessageAsync(CheckUserAndChannelForMessage(message =>
                                                                                                MentionUtils.TryParseChannel(message.Content, out channel)));

            if (!result.IsSuccess)
            {
                _logging.Error("Setup command timed out...");
                return;
            }

            await SendChannelMessage(
                $"**Set logging channel as {MentionUtils.MentionChannel(channel)}...**");
            await SendChannelMessage(
                $"**What are the staff roles? (Type `skip` to skip)**");

            IEnumerable <ulong> roles = new List <ulong>();

            result = await _interactivity.NextMessageAsync(CheckUserAndChannelForMessage(message =>
            {
                try
                {
                    if (message.Content == "skip")
                    {
                        return(true);
                    }

                    _logging.Verbose($"Roles: {message.Content}");
                    roles = message.MentionedRoles.Select(x => x.Id);
                }
                catch (Exception)
                {
                    _logging.Verbose("Role parsing error!");
                    return(false);
                }

                return(true);
            }));

            if (!result.IsSuccess)
            {
                _logging.Error("Setup command timed out...");
                return;
            }

            var guildConfig = new GuildConfigModel(Context.Guild.Id, channel, roles.ToImmutableHashSet());
            await _repo.StoreGuildConfig(guildConfig);

            _logging.Info("Successfully completed setup!");
            await SendChannelMessage(
                $"**Sucessfully completed setup!**");
            await SendChannelMessage(embed : CreateConfigInfoEmbedLog(guildConfig));
        }
Esempio n. 6
0
 public Task <InteractivityResult <SocketMessage> > NextMessageAsync(TimeSpan?timeout = null)
 {
     return(InteractivityService.NextMessageAsync(timeout: timeout));
 }