Пример #1
0
        public Embed GetEmbed(DiscordMessageContext context)
        {
            var builer = new EmbedBuilder
            {
                Title       = "Poll",
                Color       = new Color(76, 175, 80),
                Description = $"Vote using `{CommandTools.GetCommandPrefix(context, context.Channel)}{(Anonymous ? $"anonvote {Id}" : "vote")} <option number|option text>`{(Anonymous ? $"\n**__ONLY VOTES FROM A DIRECT MESSAGE TO ME WILL BE COUNTED!__**\nThis is **anonymous poll number #{Id}.**" : "")}",
                Footer      = new EmbedFooterBuilder
                {
                    Text = $"The poll will end in {TimeSpan.FromMinutes(MinutesLeft).ToLongString()} unless stopped earlier with '{CommandTools.GetCommandPrefix(context, context.Channel)}endpoll'"
                },
                Author = new EmbedAuthorBuilder
                {
                    Name    = Creator.NicknameOrUsername(),
                    IconUrl = Creator.AvatarUrlOrDefaultAvatar()
                }
            };

            for (int i = 0; i < Options.Count; i++)
            {
                builer.AddField((i + 1).ToString(), Options[i].Text, true);
            }

            if (TotalVotes > 0)
            {
                builer.AddField("Already Voted", string.Join(", ", Voters.Select(voter => voter.Key.NicknameOrUsername())));
            }

            return(builer.Build());
        }
Пример #2
0
        public static async Task <ICommandResult> DynamicMessage(DiscordUserMessageContext context, [DisplayName("interval (minutes)"), HelpText("How often to run the command")] ulong interval, [JoinRemainingParameters, HelpText("The command to run")] string command)
        {
            if (interval == 0)
            {
                return(new ErrorResult("Interval must be greater than zero"));
            }

            var message = await context.Channel.SendMessageAsync($"Loading dynamic message with command '{command}'");

            List <DynamicMessageInfo> dynamicMessages = context.Bot.DynamicMessages.Messages ?? new List <DynamicMessageInfo>();

            dynamicMessages.Add(new DynamicMessageInfo
            {
                GuildId        = context.Guild.Id,
                ChannelId      = message.Channel.Id,
                MessageId      = message.Id,
                UpdateInterval = interval,
                CommandText    = command
            });
            context.Bot.DynamicMessages.Messages = dynamicMessages;
            context.Bot.DynamicMessages.SaveConfig();

            await message.ModifyAsync(msg => msg.Content = "Loading complete, this message will be updated with dynamic content Soon:tm:");

            var dynamicMessageContext = new DiscordDynamicMessageContext(message, context.Bot, command);
            await CommandRunner.Run(command, dynamicMessageContext, CommandTools.GetCommandPrefix(dynamicMessageContext, message.Channel), false);

            return(new SuccessResult());
        }
Пример #3
0
        private async Task Client_ReactionAdded(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            if (arg3.UserId != Client.CurrentUser.Id)
            {
                var msg = await arg1.GetOrDownloadAsync();

                if (msg.Embeds.Count == 1 && !currentlyEditing.Contains(msg.Id) && PaginatedCommand.FooterRegex.IsMatch(msg.Embeds.First().Footer?.Text ?? ""))
                {
                    currentlyEditing.Add(msg.Id);
                    var    context = new DiscordPaginatedMessageContext(arg3.Emote, msg, this);
                    string prefix  = CommandTools.GetCommandPrefix(context, arg2);
                    await CommandRunner.Run($"{prefix}{context.Command} {context.UpdatedPageNumber}", context, prefix, true);

                    currentlyEditing.Remove(msg.Id);
                }
            }
        }
Пример #4
0
        private async Task Client_MessageReceived(SocketMessage arg)
        {
            var    context       = new DiscordUserMessageContext((IUserMessage)arg, this);
            string commandPrefix = CommandTools.GetCommandPrefix(context, context.Channel);
            var    status        = Statuses.Statuses.GetValueOrDefault(arg.Author.Id) ??
                                   new UserStatusInfo
            {
                StatusLastChanged = DateTimeOffset.MinValue,
                LastOnline        = DateTimeOffset.MinValue,
                Game            = null,
                StartedPlaying  = null,
                LastMessageSent = DateTimeOffset.MinValue
            };

            status.LastMessageSent           = DateTimeOffset.Now;
            Statuses.Statuses[arg.Author.Id] = status;
            if (arg.Content.Trim().StartsWith(commandPrefix) && !arg.Author.IsBot)
            {
                await CommandRunner.Run(arg.Content, context, commandPrefix, false);
            }
        }
Пример #5
0
        private async void MinuteTimer(ulong minute)
        {
            Statuses.SaveConfig();

            bool countdownsModified = false;

            foreach (ulong guild in Countdowns.Countdowns.Keys)
            {
                ulong?channel = (Countdowns.CountdownChannels?.ContainsKey(guild) ?? false) ? Countdowns.CountdownChannels[guild] : (ulong?)null;
                if (channel == null)
                {
                    continue;
                }
                foreach (var countdown in Countdowns.Countdowns[guild])
                {
                    if (countdown.Value < DateTimeOffset.Now)
                    {
                        await((ITextChannel)Client.GetChannel(channel.Value)).SendMessageAsync("", embed: CommandTools.GenerateCountdownCompleteEmbed(this, countdown.Key, countdown.Value).Build());
                        countdownsModified = true;
                    }
                }
            }

            if (countdownsModified)
            {
                foreach (ulong guild in Countdowns.Countdowns.Keys)
                {
                    foreach (string key in Countdowns.Countdowns[guild].Where(x => x.Value < DateTimeOffset.Now).Select(x => x.Key).ToArray())
                    {
                        Countdowns.Countdowns[guild].Remove(key);
                    }
                }
                Countdowns.SaveConfig();
            }

            foreach (var reminder in Reminders.Reminders.Where(reminder => reminder.Timestamp < DateTimeOffset.Now))
            {
                EmbedBuilder embed = new EmbedBuilder
                {
                    Author = new EmbedAuthorBuilder
                    {
                        Name    = $"{Client.GetUser(reminder.SenderId)?.Username ?? "Someone"} sent you a reminder",
                        IconUrl = Client.GetUser(reminder.SenderId)?.AvatarUrlOrDefaultAvatar()
                    },
                    Description  = reminder.Message,
                    ThumbnailUrl = "http://icons.iconarchive.com/icons/webalys/kameleon.pics/512/Bell-icon.png",
                    Timestamp    = reminder.Timestamp,
                    Color        = new Color(224, 79, 95)
                };

                var message = await Client.GetUser(reminder.ReceiverId).SendMessageAsync("", embed: embed.Build());

                await message.AddReactionAsync(new Emoji("💤"));
            }

            Reminders.Reminders.RemoveAll(x => x.Timestamp < DateTimeOffset.Now);
            Reminders.SaveConfig();

            if (DynamicMessages.Messages != null)
            {
                foreach (var message in DynamicMessages.Messages)
                {
                    try
                    {
                        if (minute % message.UpdateInterval != 0)
                        {
                            continue;
                        }

                        var channel        = (IMessageChannel)Client.GetGuild(message.GuildId).GetChannel(message.ChannelId);
                        var discordMessage = (IUserMessage)await channel.GetMessageAsync(message.MessageId);

                        if (discordMessage == null)
                        {
                            DynamicMessages.Messages.Remove(message);
                            continue;
                        }

                        var    context = new DiscordDynamicMessageContext(discordMessage, this, message.CommandText);
                        string prefix  = CommandTools.GetCommandPrefix(context, channel);
                        if (message.CommandText.StartsWith(prefix))
                        {
                            await CommandRunner.Run(message.CommandText, context, prefix, false);
                        }
                        else
                        {
                            await context.ReplyError($"The string `{message.CommandText}`", "Invalid Command");
                        }
                    }
                    catch
                    {
                        // Fail silently
                    }
                }

                DynamicMessages.SaveConfig();
            }
        }
Пример #6
0
        private async void SecondTimer(ulong tick)
        {
            bool  abort = false;
            Regex descriptionCommandRegex = new Regex("{{(.*?)}}");

            if (ChannelDescriptions.Descriptions != null)
            {
                foreach (var item in ChannelDescriptions.Descriptions)
                {
                    var channel = (ITextChannel)Client.GetChannel(item.Key);
                    if (channel == null)
                    {
                        ChannelDescriptions.Descriptions.Remove(item.Key);
                        ChannelDescriptions.SaveConfig();
                        continue;
                    }
                    string topic   = item.Value;
                    string newDesc = await descriptionCommandRegex.ReplaceAsync(
                        topic,
                        async m =>
                    {
                        var context = new DiscordChannelDescriptionContext(m.Groups[1].Value, channel, this);
                        var result  = await CommandRunner.RunTimer(m.Groups[1].Value, context, CommandTools.GetCommandPrefix(context, channel as IMessageChannel), true, tick);
                        abort       = result == null;
                        return(result?.ToString().Trim() ?? "");
                    });

                    if (abort)
                    {
                        continue;
                    }

                    try
                    {
                        await channel.ModifyAsync(ch => ch.Topic = newDesc);
                    }
                    catch
                    {
                        // Fail silently
                    }
                }
            }
        }