コード例 #1
0
        public async Task RemoveQuote(int id)
        {
            var   Author = Context.Message.Author as IGuildUser;
            Quote q      = _qouteRepo.GetQuoteById(id);

            if (q == null)
            {
                throw new QouteNotFound();
            }

            if (Author.GuildPermissions.ManageNicknames || q.Creator.Id == Author.Id || q.Qoutee.Id == Author.Id)
            {
                var users = await GetGuildUsers(q);

                IGuildUser quotee = users[0];
                IGuildUser quoter = users[1];

                _qouteRepo.RemoveQuote(id);
                _scoreRepo.Decrement(quotee, ScoreType.Qouted);
                _scoreRepo.Decrement(quoter, ScoreType.Qouter);

                _qouteRepo.SaveChanges();

                await Context.Channel.SendMessageAsync($"Quote {q.Id} \"{q.QuoteText.RemoveAbuseCharacters()}\" by {quotee.Nickname??quotee.Username} deleted");
            }
            else
            {
                await Context.Channel.SendMessageAsync("You can't delete someone elses quotes");
            }
        }