Beispiel #1
0
        public async Task <string> DeleteQuote(CommandMessage message, IUser user, int quoteId)
        {
            if (message.Author != user && CommandsService.GetPermissions(message.Author) != Permissions.Administrators)
            {
                throw new UserException("You don't have permission to do that.");
            }

            Dictionary <string, object> filters = new Dictionary <string, object>
            {
                { "UserId", user.Id },
                { "GuildId", message.Guild.Id },
                { "QuoteId", quoteId },
            };

            List <Quote> allQuotes = await this.quoteDb.LoadAll(filters);

            if (allQuotes.Count <= 0)
            {
                throw new UserException("I couldn't find that quote from that user.");
            }

            foreach (Quote quote in allQuotes)
            {
                await this.quoteDb.Delete(quote);
            }

            return("Quote deleted!");
        }
Beispiel #2
0
        public Task <string> Blame(CommandMessage message)
        {
            if (message.Channel is SocketGuildChannel guildChannel)
            {
                List <IGuildUser> targets = new List <IGuildUser>();
                targets.Add(message.Author);

                foreach (SocketGuildUser tTarget in guildChannel.Guild.Users)
                {
                    if (CommandsService.GetPermissions(tTarget) != Permissions.Administrators)
                    {
                        continue;
                    }

                    targets.Add(tTarget);
                }

                Random     rnd    = new Random();
                int        val    = rnd.Next(targets.Count);
                IGuildUser target = targets[val];

                if (target.Id == Program.DiscordClient.CurrentUser.Id)
                {
                    return(Task.FromResult("This is my fault. =("));
                }

                return(Task.FromResult("This is your fault, " + target.GetName() + "."));
            }

            return(Task.FromResult("This is your fault, " + message.Author.GetName() + "."));
        }
Beispiel #3
0
        public async Task ClosePoll(CommandMessage message, ulong messageId)
        {
            if (!this.pollLookup.ContainsKey(messageId))
            {
                throw new UserException("I couldn't find that poll");
            }

            string pollId = this.pollLookup[messageId];
            Poll?  poll   = await this.pollDatabase.Load(pollId);

            if (poll == null)
            {
                throw new Exception("Poll missing from database: \"" + pollId + "\"");
            }

            if (CommandsService.GetPermissions(message.Author) == Permissions.Everyone)
            {
                if (poll.Author != message.Author.Id)
                {
                    throw new UserException("I'm sorry, only the polls author, or an administrator can do that.");
                }
            }

            await poll.Close();

            this.pollLookup.Remove(poll.MessageId);
            await this.pollDatabase.Delete(poll);

            await poll.UpdateMessage();
        }
Beispiel #4
0
        public static Task <Embed> GetHelp(CommandMessage message, string?command = null)
        {
            StringBuilder builder     = new StringBuilder();
            Permissions   permissions = CommandsService.GetPermissions(message.Author);

            if (command == null)
            {
                command = message.Command;
            }

            builder.AppendLine(GetHelp(message.Guild, command, permissions));

            EmbedBuilder embed = new EmbedBuilder();

            embed.Description = builder.ToString();

            if (string.IsNullOrEmpty(embed.Description))
            {
                throw new UserException("I'm sorry, you don't have permission to use that command.");
            }

            return(Task.FromResult(embed.Build()));
        }
Beispiel #5
0
        private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> incomingMessage, ISocketMessageChannel channel, SocketReaction reaction)
        {
            try
            {
                // Don't react to your own reacts!
                if (reaction.UserId == Program.DiscordClient.CurrentUser.Id)
                {
                    return;
                }

                // Only handle reacts to help embed
                if (!activeHelpEmbeds.ContainsKey(incomingMessage.Id))
                {
                    return;
                }

                ActiveHelp helpWindow = activeHelpEmbeds[incomingMessage.Id];
                helpWindow.LastInteractedWith = DateTime.Now;

                // Only handle reacts from the original user, remove the reaction
                if (helpWindow.UserId != reaction.UserId)
                {
                    IUserMessage message = await incomingMessage.DownloadAsync();

                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    return;
                }

                // Only handle relevant reacts
                if (!HelpEmotes.Contains(reaction.Emote))
                {
                    IUserMessage message = await incomingMessage.DownloadAsync();

                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    return;
                }

                if (channel is SocketGuildChannel guildChannel)
                {
                    IUserMessage message = await incomingMessage.DownloadAsync();

                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    // Adjust current page
                    if (reaction.Emote.Equals(First))
                    {
                        helpWindow.CurrentPage = 0;
                    }
                    else if (reaction.Emote.Equals(Previous))
                    {
                        helpWindow.CurrentPage -= 1;
                    }
                    else if (reaction.Emote.Equals(Next))
                    {
                        helpWindow.CurrentPage += 1;
                    }
                    else if (reaction.Emote.Equals(Last))
                    {
                        helpWindow.CurrentPage = -1;
                    }

                    Permissions permissions = CommandsService.GetPermissions(message.GetAuthor());

                    int   currentPage = helpWindow.CurrentPage;
                    Embed embed       = GetHelp(message.GetGuild(), permissions, helpWindow.CurrentPage, out currentPage);

                    // Update current page
                    helpWindow.CurrentPage = currentPage;

                    await message.ModifyAsync(x => x.Embed = embed);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Beispiel #6
0
        public async Task <bool> Help(CommandMessage message)
        {
            Permissions permissions = CommandsService.GetPermissions(message.Author);

            return(await GetHelp(message, permissions));
        }