public async Task BanAsync( [Summary("The user to ban.")] GuildUserProxy user, [Summary("The reason why to ban the user."), Remainder] string reason = DefaultReason) { if (user.HasValue) { await user.GuildUser.TrySendMessageAsync($"You were banned from **{Context.Guild.Name}** because of {reason}."); } await Context.Guild.AddBanAsync(user.ID, _pruneDays, reason); Infraction infraction = Infraction.Create(Moderation.RequestInfractionID()) .WithType(InfractionType.Ban) .WithModerator(Context.User) .WithDescription(reason); // Normally it would be preferred to use the AddInfraction(IUser, Infraction) method but that one implicitly // sends a DM to the target which will not be in the server anymore at this point AND this method already // attempts to send a DM to the target. Moderation.AddInfraction(user.ID, infraction); await ModerationLog.CreateEntry(ModerationLogEntry.New .WithInfractionId(infraction.ID) .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.Ban) .WithTarget(user.ID) .WithReason(reason), Context.Channel); }
public async Task KickUser( [Summary("The user to kick.")] GuildUserProxy user, [Summary("The reason to kick the user for."), Remainder] string reason = DefaultReason) { if (!user.HasValue) { throw new ArgumentException($"User with ID {user.ID} is not in the server!"); } await user.GuildUser.KickAsync(reason); Infraction infraction = Infraction.Create(Moderation.RequestInfractionID()) .WithType(InfractionType.Kick) .WithModerator(Context.User) .WithDescription(reason); if (user.HasValue) { Moderation.AddInfraction(user.GuildUser, infraction); } else { Moderation.AddInfraction(user.ID, infraction); } await ModerationLog.CreateEntry(ModerationLogEntry.New .WithInfractionId(infraction.ID) .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.Kick) .WithReason(reason) .WithTarget(user), Context.Channel); }
public async Task MuteAsync( [Summary("The user to mute.")] GuildUserProxy user, [Summary("The reason why to mute the user."), Remainder] string reason = DefaultReason) { if (!user.HasValue) { throw new ArgumentException($"User with ID {user.ID} is not in the server!"); } await user.GuildUser.MuteAsync(Context); SetUserMuted(user.ID, true); Infraction infraction = Infraction.Create(Moderation.RequestInfractionID()) .WithType(InfractionType.Mute) .WithModerator(Context.User) .WithDescription(reason); Moderation.AddInfraction(user.GuildUser, infraction); await ModerationLog.CreateEntry(ModerationLogEntry.New .WithInfractionId(infraction.ID) .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.Mute) .WithTarget(user) .WithReason(reason), Context.Channel); }
public async Task TempmuteAsync( [Summary("The user to mute.")] GuildUserProxy user, [Summary("The duration for the mute."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration, [Summary("The reason why to mute the user."), Remainder] string reason = DefaultReason) { if (!user.HasValue) { throw new ArgumentException($"User with ID {user.ID} is not in the server!"); } bool unlimitedTime = (Context.User as IGuildUser).GetPermissionLevel(Data.Configuration) >= PermissionLevel.Moderator; double givenDuration = duration.TotalMilliseconds; int maxHelperMuteDuration = Data.Configuration.HelperMuteMaxDuration; if (!unlimitedTime && givenDuration > maxHelperMuteDuration) { duration = TimeSpan.FromMilliseconds(maxHelperMuteDuration); } await user.GuildUser.MuteAsync(Context); SetUserMuted(user.ID, true); Infraction infraction = Moderation.AddTemporaryInfraction(TemporaryInfractionType.TempMute, user.GuildUser, Context.User, duration, reason); await ModerationLog.CreateEntry(ModerationLogEntry.New .WithInfractionId(infraction.ID) .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.TempMute) .WithTarget(user) .WithDuration(duration) .WithReason(reason), Context.Channel); }
public async Task ClearInfractionsAsync( [Summary("The user to clear the infractions from.")] GuildUserProxy user) { ulong userId = user.HasValue ? user.GuildUser.Id : user.ID; int clearedInfractions = Moderation.ClearInfractions(userId); EmbedBuilder builder = GetDefaultBuilder() .WithColor(Color.Green); if (user.HasValue) { builder.WithDescription($"**{clearedInfractions}** infraction(s) were cleared from {user.GuildUser}."); } else { builder.WithDescription($"**{clearedInfractions}** infraction(s) were cleared from {userId}."); } await builder.Build() .SendToChannel(Context.Channel); if (clearedInfractions > 0) { await ModerationLog.CreateEntry(ModerationLogEntry.New .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.ClearInfractions) .WithTarget(userId)); } }
public override async Task <TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) { // Try to get the result from the base user reader. // If that fails, try to solely parse the ID. TypeReaderResult result = await base.ReadAsync(context, input, services); if (result.IsSuccess) { IGuildUser user = result.BestMatch as IGuildUser; GuildUserProxy proxy = new GuildUserProxy { GuildUser = user, ID = user.Id }; return(TypeReaderResult.FromSuccess(proxy)); } else { if (MentionUtils.TryParseUser(input, out ulong userId) || ulong.TryParse(input, out userId)) { return(TypeReaderResult.FromSuccess(new GuildUserProxy { ID = userId })); } } return(TypeReaderResult.FromError(CommandError.ObjectNotFound, "User not found.")); }
public async Task UnbanAsync( [Summary("The user ID to unban.")] GuildUserProxy user) { await Context.Guild.RemoveBanAsync(user.ID); Moderation.ClearTemporaryInfraction(TemporaryInfractionType.TempBan, user.ID); await ModerationLog.CreateEntry(ModerationLogEntry.New .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.Unban) .WithTarget(user.ID), Context.Channel); }
public async Task BanAsync( [Summary("The user to ban.")] GuildUserProxy user, [Summary("The reason why to ban the user."), Remainder] string reason = DefaultReason) { if (user.HasValue) { await user.GuildUser.TrySendMessageAsync($"You were banned from **{Context.Guild.Name}** because of {reason}."); } await Context.Guild.AddBanAsync(user.ID, _pruneDays, reason); await ModerationLog.CreateEntry(ModerationLogEntry.New .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.Ban) .WithTarget(user.ID) .WithReason(reason), Context.Channel); }
public async Task BanAsync( [Summary("The user to ban")] GuildUserProxy user, [Summary("The duration for the ban."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration, [Summary("The reason why to ban the user."), Remainder] string reason = DefaultReason) { // Since the user cannot be found (we are using the GuildUserProxy) we don't need to attempt to message him await Context.Guild.AddBanAsync(user.ID, _pruneDays, reason); Moderation.AddTemporaryInfraction(TemporaryInfractionType.TempBan, user.ID, Context.User, duration, reason); await ModerationLog.CreateEntry(ModerationLogEntry.New .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.TempBan) .WithTarget(user.ID) .WithDuration(duration) .WithReason(reason), Context.Channel); }
public async Task UnmuteAsync( [Summary("The user to unmute.")] GuildUserProxy user) { if (!user.HasValue) { throw new ArgumentException($"User with ID {user.ID} is not in the server!"); } await user.GuildUser.UnmuteAsync(Context); SetUserMuted(user.ID, false); Moderation.ClearTemporaryInfraction(TemporaryInfractionType.TempMute, user.GuildUser); await ModerationLog.CreateEntry(ModerationLogEntry.New .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.Unmute) .WithTarget(user), Context.Channel); }
public async Task WarnUserAsync( [Summary("The user to warn.")] GuildUserProxy user, [Summary("The reason to warn the user."), Remainder] string reason) { ulong userId = user.HasValue ? user.GuildUser.Id : user.ID; UserData data = Data.UserData.GetUser(userId); EmbedBuilder builder = new EmbedBuilder() .WithColor(Color.Orange); bool printInfractions = data != null && data.Infractions?.Count > 0; string previousInfractions = null; // Collect the previous infractions before applying new ones, otherwise we will also collect this // new infraction when printing them if (printInfractions) { previousInfractions = string.Join('\n', data.Infractions.OrderByDescending(i => i.Time).Select(i => i.ToString())); } Infraction infr = Infraction.Create(Moderation.RequestInfractionID()) .WithType(InfractionType.Warning) .WithModerator(Context.User) .WithDescription(reason); if (user.HasValue) { Moderation.AddInfraction(user.GuildUser, infr); } else { Moderation.AddInfraction(user.ID, infr); } await ModerationLog.CreateEntry(ModerationLogEntry.New .WithInfractionId(infr.ID) .WithDefaultsFromContext(Context) .WithActionType(ModerationActionType.Warn) .WithReason(reason) .WithTarget(user) .WithAdditionalInfo(previousInfractions), Context.Channel); }
public override async Task <TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services) { // Try to get the result from the base user reader. // If that fails, try to solely parse the ID. TypeReaderResult result = await base.ReadAsync(context, input, services); if (result.IsSuccess) { IGuildUser user = result.BestMatch as IGuildUser; GuildUserProxy proxy = new GuildUserProxy { GuildUser = user, ID = user.Id }; return(TypeReaderResult.FromSuccess(proxy)); } else { bool validSnowFlake = false; ulong userId = 0; if (ulong.TryParse(input, out userId)) { validSnowFlake = SnowflakeUtils.FromSnowflake(userId).ToUnixTimeSeconds() > DISCORD_START_UNIX; } if (validSnowFlake || MentionUtils.TryParseUser(input, out userId)) { return(TypeReaderResult.FromSuccess(new GuildUserProxy { ID = userId })); } } return(TypeReaderResult.FromError(CommandError.ObjectNotFound, "User not found.")); }
public async Task GetInfractionsAsync( [Summary("The user to get the infractions for.")] GuildUserProxy user) { ulong userId = user.HasValue ? user.GuildUser.Id : user.ID; UserData data = Data.UserData.GetUser(userId); EmbedBuilder builder = new EmbedBuilder() .WithColor(Color.DarkerGrey); if (data != null && data.Infractions?.Count > 0) { if (user.HasValue) { builder.WithAuthor($"{user.GuildUser} has {data.Infractions.Count} infraction(s)", user.GuildUser.EnsureAvatarUrl()); } else { builder.WithAuthor($"{user.ID} has {data.Infractions.Count} infraction(s)"); } builder.WithDescription(string.Join('\n', data.Infractions.OrderByDescending(i => i.Time).Select(i => i.ToString()))); } else { if (user.HasValue) { builder.WithAuthor($"{user.ID.Mention()} has no infractions", user.GuildUser.EnsureAvatarUrl()); } else { builder.WithAuthor($"{user.ID} has no infractions"); } } await builder.Build().SendToChannel(Context.Channel); }
public ModerationLogEntry WithTarget(GuildUserProxy target) => target.HasValue ? WithTarget(target.GuildUser) : WithTarget(target.ID);
public async Task MuteAsync( [Summary("The user to mute.")] GuildUserProxy user, [Summary("The duration for the mute."), OverrideTypeReader(typeof(AbbreviatedTimeSpanTypeReader))] TimeSpan duration, [Summary("The reason why to mute the user."), Remainder] string reason = DefaultReason) => await TempmuteAsync(user, duration, reason);