public async Task DeleteEmojiToReactionMessage(CommandContext ctx, DiscordEmoji emoji) { 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 delete reactions from a message"); return; } if (!state.ReactionMessage.Rules.ContainsKey(emoji)) { await ctx.RespondAsync("This emoji isn't associated to a role"); return; } state.ReactionMessage.Rules.Remove(emoji); }
public async Task AddRole(CommandContext ctx, DiscordRole role) { 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; } JoinRole joinRole = new JoinRole(role); if (associatedJoinRoles.Roles.Contains(joinRole)) { await ctx.RespondAsync("This role was already added"); return; } associatedJoinRoles.Roles.Add(joinRole); await ctx.RespondAsync($"Added {role.Name} to the roles to add when a person joins"); _joinRolesInteractions.SaveToFile(); }
public async Task PreviewReactionMessage(CommandContext ctx) { 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 before previewing the result"); return; } if (state.ReactionMessage.Rules.Count == 0) { await ctx.RespondAsync("You need to add at least 1 reaction and role to finish the setup"); return; } await ctx.RespondAsync(state.ReactionMessage.ToString()); }
public async Task CheckReactionMessage(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; } await ctx.TriggerTypingAsync(); await _reactionInteractions.CheckAllRules(associatedReactionMessage); await ctx.RespondAsync("Done"); }
public async Task RestartSetup(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 restart"); return; } if (state.IsInSetupMode) { state.ReactionMessage.Rules = new Dictionary <DiscordEmoji, DiscordRole>(); } else if (state.IsInEditMode) { state.ReactionMessage = new ReactionMessage(); state.ReactionMessage.Message = state.OriginalReactionMessage.Message; foreach (KeyValuePair <DiscordEmoji, DiscordRole> rule in state.OriginalReactionMessage.Rules) { state.ReactionMessage.Rules.Add(rule.Key, rule.Value); } } await ctx.RespondAsync("Restarted setup / edit"); }
public async Task StartSetup(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } await ctx.RespondAsync("You need to provide a message id to start the setup"); }
public async Task RemoveRole(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } await ctx.RespondAsync("You need to provide a mention to the role for this command"); }
public async Task FinishSetup(CommandContext ctx) { 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 before finishing it"); return; } if (state.ReactionMessage.Rules.Count == 0) { await ctx.RespondAsync("You need to have at least 1 reaction and role to finish the setup / edit"); return; } if (state.IsInEditMode) { _reactionInteractions.ReactionMessages.Remove(state.OriginalReactionMessage); } _reactionInteractions.ReactionMessages.Add(state.ReactionMessage); _reactionInteractions.SaveToFile(); string rulesString = ""; foreach (KeyValuePair <DiscordEmoji, DiscordRole> rule in state.ReactionMessage.Rules) { rulesString += rule.Key + " : " + rule.Value.Name + '\n'; try { await state.ReactionMessage.Message.CreateReactionAsync(rule.Key); } catch (Exception e) { await ctx.RespondAsync(e.ToString()); throw; } } await ctx.RespondAsync( $"Setup / edit finished!\nMessage : {state.ReactionMessage.Message.JumpLink}\nRules :\n{rulesString}"); state.ReactionMessage = new ReactionMessage(); state.OriginalReactionMessage = new ReactionMessage(); state.IsInSetupMode = false; state.IsInEditMode = false; }
public async Task RemoveReactionMessage(CommandContext ctx) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } await ctx.RespondAsync("You need to provide the original message id you want to delete"); }
public async Task DeleteEmojiToReactionMessage(CommandContext ctx, params string[] rest) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } await ctx.RespondAsync("You need to provide an emoji to delete from the message"); }
public async Task AddEmojiToReactionMessage(CommandContext ctx, params string[] rest) { if (!await CommandHelpers.CheckPermissions(ctx, RequiredPermissions)) { return; } await ctx.RespondAsync("You need to provide an emoji and mention the role to attribute it to"); }
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 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 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"); }