public async Task RemoveReputation(CommandMessage message, IGuildUser user) { // Handle bots if (user.IsBot) { await message.Channel.SendMessageAsync("Bots cannot gain reputation.", messageReference : message.MessageReference); return; } // Get leaderboard settings LeaderboardSettings settings = await LeaderboardSettingsService.GetSettings <LeaderboardSettings>(message.Guild.Id); if (settings.ReputationRemoveRole == "0") { // Rep disabled on server await message.Channel.SendMessageAsync("Rep Removal has been disabled by Server Admin", messageReference : message.MessageReference); return; } else if (settings.ReputationRemoveRole != "1") { // Rep role required to remove if (ulong.TryParse(settings.ReputationRemoveRole, out ulong repRole) && !message.Author.RoleIds.Contains(repRole)) { // Rep Role required to remove not assigned to user await message.Channel.SendMessageAsync("You do not have permission to remove Rep.", messageReference : message.MessageReference); return; } } // Get sending user information User fromUser = await UserService.GetUser(message.Author); string fromUserName = message.Author.GetName(); // Get receiving user information User toUser = await UserService.GetUser(user); string toUserName = user.GetName(); // Message for return string postBackMessage; if (fromUser.Id == toUser.Id) { postBackMessage = "You can't remove your own rep, _kupo!_"; } else { // Update user information toUser.Reputation -= 1; _ = UserService.SaveUser(toUser); postBackMessage = $"Hey {toUserName}, {fromUserName} thinks you've done bad, _kupo!_\nYour rep is now: {toUser.Reputation}"; } await message.Channel.SendMessageAsync(postBackMessage, messageReference : message.MessageReference); return; }
public async Task GiveReputation(CommandMessage message, IGuildUser user) { // Handle bots if (user.IsBot) { // Thank user if trying to rep Kupo Nuts or tell them no if repping a different bot string botMessage = user.Id == Program.DiscordClient.CurrentUser.Id ? string.Format("I think you're pretty neat too, _kupo!_") : string.Format("They wouldn't understand..."); await message.Channel.SendMessageAsync(botMessage, messageReference : message.MessageReference); return; } // Get leaderboard settings LeaderboardSettings settings = await LeaderboardSettingsService.GetSettings <LeaderboardSettings>(message.Guild.Id); if (settings.ReputationAddRole == "0") { // Rep disabled on server await message.Channel.SendMessageAsync("Rep has been disabled by Server Admin", messageReference : message.MessageReference); return; } else if (settings.ReputationAddRole != "1") { // Rep role required to add if (ulong.TryParse(settings.ReputationAddRole, out ulong repRole) && !message.Author.RoleIds.Contains(repRole)) { // Rep Role required to add not assigned to user await message.Channel.SendMessageAsync("You do not have permission to add Rep.", messageReference : message.MessageReference); return; } } // Get sending user information User fromUser = await UserService.GetUser(message.Author); string fromUserName = message.Author.GetName(); // Get receiving user information User toUser = await UserService.GetUser(user); string toUserName = user.GetName(); // Daily reset at 8AM DateTime dailyReset = DateTime.Now.Date.AddHours(8); // Check if it's too early if (DateTime.Now < dailyReset) { dailyReset = dailyReset.AddDays(-1); } // Message for return string postBackMessage; // If rep limit is disabled or user has not repped today if (!settings.LimitReputationPerDay || !fromUser.LastRepGiven.HasValue || fromUser.LastRepGiven < dailyReset) { if (fromUser.Id == toUser.Id) { postBackMessage = "You can't rep yourself, _kupo!_"; } else { // Update user information fromUser.LastRepGiven = DateTime.Now; _ = UserService.SaveUser(fromUser); toUser.Reputation += 1; _ = UserService.SaveUser(toUser); postBackMessage = $"Hey {toUserName}, {fromUserName} thinks you're pretty neat, _kupo!_\nYour rep is now: {toUser.Reputation}"; } } else { postBackMessage = "You have already given your rep today!"; } await message.Channel.SendMessageAsync(postBackMessage, messageReference : message.MessageReference); return; }