Beispiel #1
0
        public async Task <RuntimeResult> Help()
        {
            IEnumerable <ModuleInfo> modules = Store.Get <IEnumerable <ModuleInfo> >();

            Embed embed = EmbedFactory.Create(builder =>
            {
                builder.WithColor(Color.Purple);
                builder.WithTitle("Help ");
                builder.WithDescription($"Commands are separated per module. To get all the commands in a module, use {Prefix}Help moduleName");

                foreach (var module in modules)
                {
                    if (module.Name == nameof(Module))
                    {
                        continue;
                    }

                    string remarks = string.IsNullOrEmpty(module.Remarks) ? string.Empty : $"({module.Remarks})";

                    builder.AddField(module.Name.Replace("Module", string.Empty), $"{(!string.IsNullOrEmpty(module.Summary) ? module.Summary : "No summary available")}\n{remarks}");
                }
            });

            return(new SuccessResult(embed));
        }
        public async Task AddDealAsync(string url, string timeLeft = null)
        {
            IEnumerable <IMessage> messages = await(Context.Channel as ITextChannel)?.GetMessagesAsync(1)?.FlattenAsync();

            await(Context.Channel as ITextChannel)?.DeleteMessagesAsync(messages);
            IUserMessage reply = await ReplyAsync("Adding your deal...");

            Deal deal = new Deal
            {
                Url  = url,
                User = User
            };

            if (timeLeft != null)
            {
                TimeSpan.TryParse(timeLeft, out TimeSpan expires);
                deal.ExpireDate = DateTime.Now.Add(expires);
            }

            Embed embed = EmbedFactory.Create(ResultType.Success, builder => {
                builder.WithTitle((messages.First() as IUserMessage).Content);
            });

            IUserMessage message = await ReplyAsync(embed);

            deal.MessageId = message.Id;

            Database.Deals.Add(deal);
        }
        public async Task <RuntimeResult> ListJokesAsync(SocketGuildUser user = null)
        {
            List <Joke> jokesList;

            if (user is null)
            {
                jokesList = await Database.Jokes
                            .OrderBy(x => Guid.NewGuid())
                            .Take(10)
                            .ToListAsync();
            }
            else
            {
                jokesList = await Database.Jokes
                            .Where(x => x.User.Id == user.Id)
                            .OrderBy(x => Guid.NewGuid())
                            .Take(10)
                            .ToListAsync();
            }

            if (jokesList.Count is 0)
            {
                return(new ErrorResult(CommandError.ObjectNotFound, "No jokes in the database"));
            }

            Embed embed = EmbedFactory.Create(ResultType.Info, builder => {
                builder.WithTitle("Here's the list of jokes");
                foreach (Joke joke in jokesList)
                {
                    builder.AddField($"{joke.Id} - {joke.Text}", $"Submitted by {joke.User.Username}");
                }
            });

            return(new InfoResult(embed));
        }
        public async Task <RuntimeResult> ShowJokeAsync(SocketGuildUser user = null)
        {
            Joke joke;

            if (user is null)
            {
                joke = await Database.Jokes
                       .OrderBy(x => Guid.NewGuid())
                       .FirstOrDefaultAsync();
            }
            else
            {
                joke = await Database.Jokes
                       .Where(x => x.User.Id == user.Id)
                       .OrderBy(x => Guid.NewGuid())
                       .FirstOrDefaultAsync();
            }

            if (joke is null)
            {
                return(new ErrorResult(CommandError.ObjectNotFound, "No jokes in the database"));
            }

            Embed embed = EmbedFactory.Create(ResultType.Info, builder => {
                builder.WithTitle($"{joke.Id} - {joke.Text}");
                builder.WithFooter($"Submitted by {joke.User.Username}", joke.User.AvatarUrl);
            });

            return(new InfoResult(embed));
        }
        public async Task <RuntimeResult> ListAlertsAsync()
        {
            List <Alert> alertList = await Database.Alerts
                                     .Where(x => x.User.Id == User.Id)
                                     .Include(x => x.User)
                                     .Include(x => x.TargetUser)
                                     .ToListAsync();

            if (alertList.Count is 0)
            {
                return(new ErrorResult("No alerts were found"));
            }

            Embed embed = EmbedFactory.Create(ResultType.Success, builder => {
                string description = "";
                foreach (Alert alert in alertList)
                {
                    description += $"Alert for **{alert.TargetUser.Username}**\n";
                }

                builder.WithDescription(description);
            });

            return(new SuccessResult(embed));
        }
Beispiel #6
0
        public async Task <RuntimeResult> ShowRandomMemeAsync()
        {
            string meme = string.Format("http://images.memes.com/meme/{0}.jpg", new Random().Next(33000));

            Embed embed = EmbedFactory.Create(ResultType.Info, builder => {
                builder.WithTitle(meme);
                builder.WithImageUrl(meme);
            });

            return(new SuccessResult(embed));
        }
Beispiel #7
0
        public async Task <RuntimeResult> Reply(SocketGuildUser userToReplyTo, int prevMessageIndex, [Remainder] string reply)
        {
            if (prevMessageIndex < 1)
            {
                return(new ErrorResult("The number telling me which message you want to reply to, must be at least 1!"));
            }

            const int messageLogLength          = 20;
            IEnumerable <IMessage> lastMessages = await Context.Channel.GetMessagesAsync(messageLogLength).FlattenAsync();

            IEnumerable <IMessage> enumerable = lastMessages as IMessage[] ?? lastMessages.ToArray();

            if (enumerable.Count() < prevMessageIndex)
            {
                return(new ErrorResult(EmbedFactory.Create(x =>
                {
                    x.CreateError($"There are less than {prevMessageIndex} messages in this channel, let alone from {userToReplyTo.Username}... Please reconsider the command!");
                })));
            }

            if (enumerable.First(x => x.Author == userToReplyTo) is null)
            {
                return(new ErrorResult(EmbedFactory.Create(x =>
                {
                    x.CreateError($"{userToReplyTo.Username} hasn't sent a message in the last {messageLogLength} messages.");
                })));
            }

            if (enumerable.Count(x => x.Author == userToReplyTo) < prevMessageIndex)
            {
                return(new ErrorResult(EmbedFactory.Create(x =>
                {
                    x.CreateError($"{userToReplyTo.Username} hasn't sent {prevMessageIndex} messages in the last {messageLogLength} messages.");
                })));
            }

            var messageToReplyTo = enumerable.Where(x => x.Author == userToReplyTo).ToArray()[prevMessageIndex - (userToReplyTo == Context.User ? 0 : 1)];

            if (messageToReplyTo.Attachments.Count > 0 || messageToReplyTo.Embeds.Count > 0)
            {
                return(new ErrorResult(EmbedFactory.Create(x =>
                {
                    x.CreateError("Sadly, I'm unable to handle replying to messages containing attachments or embeds... sorry 😕");
                })));
            }

            return(new InfoResult(EmbedFactory.Create(x =>
            {
                x.WithColor(Color.Purple);
                x.WithDescription(userToReplyTo.Mention);
                x.AddField("Original:", messageToReplyTo.Content);
                x.AddField("Reply:", reply);
            })));
        }
Beispiel #8
0
        public async Task <RuntimeResult> ShowDefaultAuditChannelAsync()
        {
            SocketTextChannel channel = Context.Client.GetChannel(Guild.AuditChannelId) as SocketTextChannel;

            if (channel is null)
            {
                return(new ErrorResult(CommandError.UnmetPrecondition, "No default audit channel set for this guild"));
            }

            Embed embed = EmbedFactory.Create(ResultType.Info, builder => {
                builder.WithTitle("Here's the audit channel");
                builder.WithDescription(channel.Mention);
            });

            return(new InfoResult(embed));
        }
Beispiel #9
0
        public async Task Info()
        {
            Embed embed = EmbedFactory.Create(x =>
            {
                x.WithColor(Color.Purple);
                x.ThumbnailUrl = Guild.IconUrl;
                x.AddField("Server Name", Guild.Name ?? "null");

                if (Guild.AuditChannelId != null)
                {
                    SocketTextChannel auditChannel = (SocketTextChannel)Context.Guild.GetChannel(Guild.AuditChannelId.Value);
                    x.AddField("Audit Channel", auditChannel != null ? auditChannel.Mention : "Invalid channel!");
                }

                x.AddField("Command prefix", Prefix);
            });

            await ReplyAsync(embed);
        }
        public async Task CreatePollAsync([Remainder] string question)
        {
            IEnumerable <IMessage> messages = await Context.Channel.GetMessagesAsync(1).FlattenAsync();

            await(Context.Channel as ITextChannel).DeleteMessagesAsync(messages);

            Embed embed = EmbedFactory.Create(ResultType.Info, builder => {
                builder.WithTitle(question);
                builder.WithFooter($"Asked by {Context.User.Username}", Context.User.GetAvatarUrl() ?? null);
            });

            IUserMessage message = await ReplyAsync(embed);

            foreach (Emoji reaction in _reactions)
            {
                await message.AddReactionAsync(reaction);

                await Task.Delay(250);
            }
        }
        public async Task <RuntimeResult> ShowDealsAsync()
        {
            List <Deal> dealList = await Database.Deals
                                   .ToListAsync();

            if (dealList.Count is 0)
            {
                return(new ErrorResult(CommandError.ObjectNotFound, "No deals were found"));
            }

            Embed embed = EmbedFactory.Create(ResultType.Success, builder => {
                builder.WithTitle("Here's the deals");

                foreach (Deal deal in dealList)
                {
                    builder.AddField($"{deal.Url}", $"{deal.ExpireDate}");
                }
            });

            return(new SuccessResult("Success", embed));
        }
Beispiel #12
0
        public async Task <RuntimeResult> ListRemindersAsync()
        {
            List <Reminder> reminderList = await Database.Reminders
                                           .Where(x => x.User.Id == User.Id)
                                           .ToListAsync();

            if (reminderList.Count is 0)
            {
                return(new ErrorResult(CommandError.ObjectNotFound, "No reminders in the database"));
            }

            Embed embed = EmbedFactory.Create(ResultType.Info, builder => {
                builder.WithTitle("Here's your reminders");
                foreach (Reminder reminder in reminderList)
                {
                    builder.AddField($"{reminder.Id} - {reminder.Message ?? "No message"}", $"{reminder.DueDate}");
                }
            });

            return(new InfoResult(embed));
        }
Beispiel #13
0
        public async Task <RuntimeResult> ListAllGamesAsync()
        {
            List <Domain.Game> gamesList = await Database.Games
                                           .ToListAsync();

            if (gamesList.Count is 0)
            {
                return(new ErrorResult(CommandError.ObjectNotFound, "No games found in the database"));
            }

            Embed embed = EmbedFactory.Create(ResultType.Info, builder => {
                builder.WithTitle("Here are the currently registered game servers");
                builder.WithCurrentTimestamp();

                foreach (Domain.Game game in gamesList)
                {
                    string st = game.IsOnline ? "Online " : "Offline ";
                    builder.AddField(game.Name, st + $"on port {game.Port}, version {game.Version}");
                }
            });

            return(new InfoResult("Info", embed));
        }
Beispiel #14
0
        public async Task <RuntimeResult> Reply(ulong messageId, [Remainder] string reply)
        {
            if (!(Context.Channel is ITextChannel currentChannel))
            {
                return(new ErrorResult(EmbedFactory.Create(x =>
                {
                    x.CreateError("Sorry, was unable to cast the current channel to ITextChannel");
                })));
            }

            IMessage message = await currentChannel.GetMessageAsync(messageId);

            if (message is null)
            {
                return(new ErrorResult(EmbedFactory.Create(x =>
                {
                    x.CreateError("Sorry, was unable to find the requested message");
                })));
            }

            if (message.Attachments.Count > 0 || message.Embeds.Count > 0)
            {
                return(new ErrorResult(EmbedFactory.Create(x =>
                {
                    x.CreateError("Sadly, I'm unable to handle replying to messages containing attachments or embeds... sorry 😕");
                })));
            }

            return(new InfoResult(EmbedFactory.Create(x =>
            {
                x.WithColor(Color.Purple);
                x.WithDescription(message.Author.Mention);
                x.AddField("Original: ", message.Content);
                x.AddField("Reply: ", reply);
            })));
        }
        public async Task <RuntimeResult> ShowActivitiesAsync()
        {
            List <Domain.Activity> activityList = await Database.Activities
                                                  .Where(x => x.User.Id == User.Id)
                                                  .ToListAsync();

            if (activityList.Count is 0)
            {
                return(new ErrorResult(CommandError.ObjectNotFound, "No activities were found"));
            }

            Embed embed = EmbedFactory.Create(ResultType.Success, builder => {
                foreach (Domain.Activity activity in activityList)
                {
                    builder.AddField(field => {
                        field.WithName(activity.Name);
                        field.WithValue(activity.Arguments);
                        field.WithIsInline(false);
                    });
                }
            });

            return(new SuccessResult(embed));
        }