public async Task TestLogging(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } await ctx.RespondAsync($"Running test... if nothing happens try setting the log channel again with {ctx.Prefix}{CommandNames.SetLoggingChannel}"); await GuildEventLogger.Instance.LogInfo(ctx.Guild, $"This is the test of the event logger as requested per [this message]({ctx.Message.JumpLink})"); }
public async Task UnsetLoggingChannel(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } GuildEventLogger.Instance.UnsetLogChannel(ctx.Guild); await ctx.RespondAsync("Unset this channel as the bot log channel"); }
public async Task ListReactionMessages(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } StringBuilder sb = new StringBuilder("Reaction Messages :"); foreach (ReactionMessage reactionMessage in _reactionInteractions.ReactionMessages.Where(x => x.Message.Channel.GuildId == ctx.Channel.GuildId)) { sb.Append("\n\n" + reactionMessage.ToString() + '\n'); } await ctx.RespondAsync(sb.ToString()); }
public async Task EditReactionMessage(CommandContext ctx, string messageUrl) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } SetupState state = _setupStates[ctx.Guild.Id]; if (state.IsInSetupMode || state.IsInEditMode) { await ctx.RespondAsync( "The bot is already setting up / editing a reaction message, finish it then try again"); return; } DiscordMessage message = await CommandHelpers.GetMessageFromUrl(ctx, messageUrl); if (message is null) { return; } ReactionMessage associatedMessage = _reactionInteractions.ReactionMessages.FirstOrDefault(x => x.Message.Equals(message)); if (associatedMessage == null) { await ctx.RespondAsync("This message doesn't have reaction interactions setup"); return; } state.ReactionMessage.Message = associatedMessage.Message; foreach (KeyValuePair <DiscordEmoji, DiscordRole> rule in associatedMessage.Rules) { state.ReactionMessage.Rules.Add(rule.Key, rule.Value); } state.OriginalReactionMessage = associatedMessage; await ctx.RespondAsync($"Got the message to edit, continue the edit with {ctx.Prefix}{CommandNames.AddEmojiToReactionMessage} (emoji) (mention to role)\nPreview the rules with {ctx.Prefix}{CommandNames.PreviewReactionMessage}"); state.IsInEditMode = true; }
public async Task LoggingInfo(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } GuildEventLogger.GuildLogInfoResult result = GuildEventLogger.Instance.GetGuildLogInfo(ctx.Guild); string response = $"Is event logging set : {result.IsSet}"; if (result.IsSet) { response += $"\nChannel where events are logged : {result.LogChannel.Mention}"; } await ctx.RespondAsync(response); }
public async Task ListRoles(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } JoinRoles associatedJoinRoles = _joinRolesInteractions.JoinRoles.FirstOrDefault(joinRoles => joinRoles.Guild == ctx.Guild); if (associatedJoinRoles == null) { await ctx.RespondAsync("JoinRoles are not enabled for this guild"); return; } await ctx.RespondAsync(associatedJoinRoles.ToString()); }
public async Task Enable(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } if (_joinRolesInteractions.JoinRoles.FirstOrDefault(x => x.Guild == ctx.Guild) != null) { await ctx.RespondAsync($"JoinRoles are already enabled for this guild"); return; } _joinRolesInteractions.JoinRoles.Add(new JoinRoles(ctx.Guild, new List <JoinRole>())); await ctx.RespondAsync( $"JoinRoles are now enabled for this guild, add roles with {ctx.Prefix}{CommandNames.AddRole}"); _joinRolesInteractions.SaveToFile(); }
public async Task AddEmojiToReactionMessage(CommandContext ctx, DiscordEmoji emoji, DiscordRole role) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } SetupState state = _setupStates[ctx.Guild.Id]; if (!state.IsInSetupMode && !state.IsInEditMode) { await ctx.RespondAsync("You need to have entered setup or edit mode to add reactions"); return; } //FIXME: This is pretty bad, try to find an other solution. //Check to see if the bot has access to the emoji or not try { await ctx.Message.CreateReactionAsync(emoji); await ctx.Message.DeleteOwnReactionAsync(emoji); } catch { await ctx.RespondAsync("This emoji is not available to the bot"); return; } if (state.ReactionMessage.Rules.ContainsKey(emoji)) { await ctx.RespondAsync("This emoji is already assigned to a role"); return; } state.ReactionMessage.Rules.Add(emoji, role); }
public async Task Disable(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } JoinRoles associatedJoinRoles = _joinRolesInteractions.JoinRoles.FirstOrDefault(joinRoles => joinRoles.Guild == ctx.Guild); if (associatedJoinRoles == null) { await ctx.RespondAsync("JoinRoles are not enabled for this guild"); return; } _joinRolesInteractions.JoinRoles.Remove(associatedJoinRoles); await ctx.RespondAsync("Disabled JoinRoles for this guild"); _joinRolesInteractions.SaveToFile(); }
public async Task RemoveReactionMessage(CommandContext ctx, string messageToUse) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } DiscordMessage message = await CommandHelpers.GetMessageFromUrl(ctx, messageToUse); if (message is null) { return; } ReactionMessage associatedReactionMessage = _reactionInteractions.ReactionMessages.FirstOrDefault(x => x.Message.Equals(message)); if (associatedReactionMessage == null) { await ctx.RespondAsync("Couldn't find the ReactionMessage associated with this Discord message"); return; } _reactionInteractions.ReactionMessages.Remove(associatedReactionMessage); await ctx.RespondAsync("Succesfully removed the corresponding ReactionMessage"); _reactionInteractions.SaveToFile(); foreach (KeyValuePair <DiscordEmoji, DiscordRole> rule in associatedReactionMessage.Rules) { try { await associatedReactionMessage.Message.DeleteOwnReactionAsync(rule.Key); } catch { } } }
public async Task StartSetup(CommandContext ctx, string messageUrl) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } SetupState state = _setupStates[ctx.Guild.Id]; if (state.IsInSetupMode || state.IsInEditMode) { await ctx.RespondAsync( "The bot is already setting up / editing a reaction message, finish the previous one and try again"); return; } DiscordMessage message = await CommandHelpers.GetMessageFromUrl(ctx, messageUrl); if (message is null) { return; } if (_reactionInteractions.ReactionMessages.FirstOrDefault(x => x.Message.Equals(message)) != null) { await ctx.RespondAsync("This message already got reaction interactions setup"); return; } state.ReactionMessage.Message = message; await ctx.RespondAsync($"Got the message to use, continue the setup with {ctx.Prefix}{CommandNames.AddEmojiToReactionMessage} (emoji) (mention to role)\nPreview the rules with {ctx.Prefix}{CommandNames.PreviewReactionMessage}"); state.IsInSetupMode = true; }
public async Task AbortSetup(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } SetupState state = _setupStates[ctx.Guild.Id]; if (!state.IsInSetupMode && !state.IsInEditMode) { await ctx.RespondAsync("Nothing to abort"); return; } state.ReactionMessage = new ReactionMessage(); state.OriginalReactionMessage = new ReactionMessage(); state.IsInSetupMode = false; state.IsInEditMode = false; await ctx.RespondAsync("Aborted setup / edit"); }