public async Task Unsudo(CommandContext ctx, [Description("Discord user on the moderator list to strip the sudoer rights from")] DiscordMember sudoer) { if (ctx.Client.CurrentApplication.Owners.Any(u => u.Id == sudoer.Id)) { var dm = await sudoer.CreateDmChannelAsync().ConfigureAwait(false); await dm.SendMessageAsync($@"Just letting you know that {ctx.Message.Author.Mention} just tried to strip you off of your sudo permissions ¯\\_(ツ)_/¯").ConfigureAwait(false); await ctx.ReactWithAsync(Config.Reactions.Denied, $"{ctx.Message.Author.Mention} why would you even try this?! Alerting {sudoer.Mention}", true).ConfigureAwait(false); } else if (ModProvider.IsMod(sudoer.Id)) { if (await ModProvider.UnmakeSudoerAsync(sudoer.Id).ConfigureAwait(false)) { await ctx.ReactWithAsync(Config.Reactions.Success, $"{sudoer.Mention} is no longer a sudoer").ConfigureAwait(false); } else { await ctx.ReactWithAsync(Config.Reactions.Failure, $"{sudoer.Mention} is not a sudoer").ConfigureAwait(false); } } else { await ctx.ReactWithAsync(Config.Reactions.Failure, $"{sudoer.Mention} is not even a moderator!").ConfigureAwait(false); } }
private async Task <bool> CheckListPermissionAsync(CommandContext ctx, ulong userId) { if (userId == ctx.Message.Author.Id || ModProvider.IsMod(ctx.Message.Author.Id)) { return(true); } await ctx.ReactWithAsync(Config.Reactions.Denied, "Regular users can only view their own warnings").ConfigureAwait(false); return(false); }
public static bool IsWhitelisted(this DiscordUser user, DiscordClient client, DiscordGuild guild = null) { if (ModProvider.IsMod(user.Id)) { return(true); } var member = guild == null?client.GetMember(user) : client.GetMember(guild, user); return(member?.Roles.IsWhitelisted() ?? false); }
public async Task Add(CommandContext ctx, [Description("Discord user to add to the bot mod list")] DiscordMember user) { if (await ModProvider.AddAsync(user.Id).ConfigureAwait(false)) { await ctx.ReactWithAsync(Config.Reactions.Success, $"{user.Mention} was successfully added as moderator!\n" + $"Try using `{ctx.Prefix}help` to see new commands available to you" ).ConfigureAwait(false); } else { await ctx.ReactWithAsync(Config.Reactions.Failure, $"{user.Mention} is already a moderator").ConfigureAwait(false); } }
public override async Task BeforeExecutionAsync(CommandContext ctx) { executionStart = DateTimeOffset.UtcNow; try { if (ctx.Prefix == Config.AutoRemoveCommandPrefix && ModProvider.IsMod(ctx.User.Id)) { DeletedMessagesMonitor.RemovedByBotCache.Set(ctx.Message.Id, true, DeletedMessagesMonitor.CacheRetainTime); await ctx.Message.DeleteAsync().ConfigureAwait(false); } } catch (Exception e) { Config.Log.Warn(e, "Failed to delete command message with the autodelete command prefix"); } if (ctx.Channel.Name == "media" && ctx.Command.QualifiedName != "warn" && ctx.Command.QualifiedName != "report") { Config.Log.Info($"Ignoring command from {ctx.User.Username} (<@{ctx.User.Id}>) in #media: {ctx.Message.Content}"); if (ctx.Member is DiscordMember member) { var dm = await member.CreateDmChannelAsync().ConfigureAwait(false); await dm.SendMessageAsync($"Only `{Config.CommandPrefix}warn` and `{Config.CommandPrefix}report` are allowed in {ctx.Channel.Mention}").ConfigureAwait(false); } Config.TelemetryClient?.TrackRequest(ctx.Command.QualifiedName, executionStart, DateTimeOffset.UtcNow - executionStart, HttpStatusCode.Forbidden.ToString(), true); throw new DSharpPlus.CommandsNext.Exceptions.ChecksFailedException(ctx.Command, ctx, new CheckBaseAttribute[] { new RequiresNotMedia() }); } var disabledCmds = DisabledCommandsProvider.Get(); if (disabledCmds.Contains(ctx.Command.QualifiedName) && !disabledCmds.Contains("*")) { await ctx.RespondAsync(embed : new DiscordEmbedBuilder { Color = Config.Colors.Maintenance, Description = "Command is currently disabled" }).ConfigureAwait(false); Config.TelemetryClient?.TrackRequest(ctx.Command.QualifiedName, executionStart, DateTimeOffset.UtcNow - executionStart, HttpStatusCode.Locked.ToString(), true); throw new DSharpPlus.CommandsNext.Exceptions.ChecksFailedException(ctx.Command, ctx, new CheckBaseAttribute[] { new RequiresDm() }); } if (TriggersTyping(ctx)) { await ctx.ReactWithAsync(Config.Reactions.PleaseWait).ConfigureAwait(false); } await base.BeforeExecutionAsync(ctx).ConfigureAwait(false); }
public static bool IsModerator(this DiscordUser?user, DiscordClient client, DiscordGuild?guild = null) { if (user == null) { return(false); } if (ModProvider.IsSudoer(user.Id)) { return(true); } var member = guild == null?client.GetMember(user) : client.GetMember(guild, user); return(member?.Roles.IsModerator() is true); }
public async Task Sudo(CommandContext ctx, [Description("Discord user on the moderator list to grant the sudoer rights to")] DiscordMember moderator) { if (ModProvider.IsMod(moderator.Id)) { if (await ModProvider.MakeSudoerAsync(moderator.Id).ConfigureAwait(false)) { await ctx.ReactWithAsync(Config.Reactions.Success, $"{moderator.Mention} is now a sudoer").ConfigureAwait(false); } else { await ctx.ReactWithAsync(Config.Reactions.Failure, $"{moderator.Mention} is already a sudoer").ConfigureAwait(false); } } else { await ctx.ReactWithAsync(Config.Reactions.Failure, $"{moderator.Mention} is not a moderator (yet)").ConfigureAwait(false); } }
public async Task Remove(CommandContext ctx, [Description("Discord user to remove from the bot mod list")] DiscordMember user) { if (ctx.Client.CurrentApplication.Owners.Any(u => u.Id == user.Id)) { var dm = await user.CreateDmChannelAsync().ConfigureAwait(false); await dm.SendMessageAsync($@"Just letting you know that {ctx.Message.Author.Mention} just tried to strip you off of your mod role ¯\\_(ツ)_/¯").ConfigureAwait(false); await ctx.ReactWithAsync(Config.Reactions.Denied, $"{ctx.Message.Author.Mention} why would you even try this?! Alerting {user.Mention}", true).ConfigureAwait(false); } else if (await ModProvider.RemoveAsync(user.Id).ConfigureAwait(false)) { await ctx.ReactWithAsync(Config.Reactions.Success, $"{user.Mention} removed as moderator!").ConfigureAwait(false); } else { await ctx.ReactWithAsync(Config.Reactions.Failure, $"{user.Mention} is not a moderator").ConfigureAwait(false); } }
public static bool IsSmartlisted(this DiscordMember member) { return(ModProvider.IsMod(member.Id) || member.Roles.IsSmartlisted()); }
protected override Task <bool> IsAllowed(CommandContext ctx, bool help) { return(Task.FromResult(ModProvider.IsSudoer(ctx.User.Id))); }
protected async Task List(CommandContext ctx, string eventName = null, int?year = null) { var showAll = "all".Equals(eventName, StringComparison.InvariantCultureIgnoreCase); var currentTicks = DateTime.UtcNow.Ticks; List <EventSchedule> events; using (var db = new BotDb()) { IQueryable <EventSchedule> query = db.EventSchedule; if (year.HasValue) { query = query.Where(e => e.Year == year); } else { if (!ctx.Channel.IsPrivate && !showAll) { query = query.Where(e => e.End > currentTicks); } } if (!string.IsNullOrEmpty(eventName) && !showAll) { eventName = await FuzzyMatchEventName(db, eventName).ConfigureAwait(false); query = query.Where(e => e.EventName == eventName); } events = await query .OrderBy(e => e.Start) .ToListAsync() .ConfigureAwait(false); } if (events.Count == 0) { await ctx.RespondAsync("There are no events to show").ConfigureAwait(false); return; } var msg = new StringBuilder(); var currentYear = -1; var currentEvent = Guid.NewGuid().ToString(); foreach (var evt in events) { if (evt.Year != currentYear) { if (currentYear > 0) { msg.AppendLine().AppendLine($"__Year {evt.Year}__"); } currentEvent = Guid.NewGuid().ToString(); currentYear = evt.Year; } var evtName = evt.EventName ?? ""; if (currentEvent != evtName) { currentEvent = evtName; var printName = string.IsNullOrEmpty(currentEvent) ? "Various independent events" : $"**{currentEvent} {currentYear} schedule**"; msg.AppendLine($"{printName} (UTC):"); } msg.Append(StringUtils.InvisibleSpacer).Append("`"); if (ModProvider.IsMod(ctx.Message.Author.Id)) { msg.Append($"[{evt.Id:0000}] "); } msg.Append($"{evt.Start.AsUtc():u}"); if (ctx.Channel.IsPrivate) { msg.Append($@" - {evt.End.AsUtc():u}"); } msg.AppendLine($@" ({evt.End.AsUtc() - evt.Start.AsUtc():h\:mm})`: {evt.Name}"); } var ch = await ctx.GetChannelForSpamAsync().ConfigureAwait(false); await ch.SendAutosplitMessageAsync(msg, blockStart : "", blockEnd : "").ConfigureAwait(false); }
public static bool IsWhitelisted(this DiscordMember member) => ModProvider.IsMod(member.Id) || member.Roles.IsWhitelisted();