/// <summary> /// Creates a new Message asking for confirmation by the user /// </summary> public static async Task <ConfirmationInteractiveMessage> CreateConfirmationMessage(string messageContent, string title, Color color, string description, IEmote confirmEmote, IEmote denyEmote, MessageInteractionDelegate onConfirm, MessageInteractionDelegate onDeny) { if (GuildChannelHelper.TryGetChannel(GuildChannelHelper.InteractiveMessagesChannelId, out SocketTextChannel channel)) { EmbedBuilder embed = new EmbedBuilder() { Title = title, Color = color, Description = description }; embed.AddField("Choices", $"{confirmEmote.Name} - Confirm\n{denyEmote.Name} - Deny"); var message = await channel.SendMessageAsync(messageContent, embed : embed.Build()); List <EmoteInteraction> interactions = new List <EmoteInteraction>(2); interactions.Add(new EmoteInteraction(confirmEmote, onConfirm, false)); interactions.Add(new EmoteInteraction(denyEmote, onDeny, false)); var result = new ConfirmationInteractiveMessage(message as IUserMessage, interactions); await message.AddReactionsAsync(new IEmote[] { confirmEmote, denyEmote }); return(result); } else { return(null); } }
private static async Task SendCommandExecutionExceptionMessage(Exception e, ReactionContext context, ReactionCommand command) { await context.Channel.SendEmbedAsync("Something went horribly wrong trying to execute your emojicommand! I have contacted my creators to help fix this issue!", true); if (GuildChannelHelper.TryGetChannel(GuildChannelHelper.DebugChannelId, out SocketTextChannel channel)) { EmbedBuilder embed = new EmbedBuilder(); embed.Color = BotCore.ErrorColor; embed.Title = "**__Exception__**"; embed.AddField("Command", command.Emote); embed.AddField("Location", context.Channel.Mention); embed.AddField("Message", Markdown.MultiLineCodeBlock(e.Message)); string stacktrace; if (e.StackTrace.Length <= 500) { stacktrace = e.StackTrace; } else { stacktrace = e.StackTrace.Substring(0, 500); } embed.AddField("StackTrace", Markdown.MultiLineCodeBlock(stacktrace)); await channel.SendMessageAsync(embed : embed.Build()); } await YNBBotCore.Logger(new LogMessage(LogSeverity.Error, "CMDSERVICE", string.Format("An Exception occured while trying to execute command `/{0}`.Message: '{1}'\nStackTrace {2}", command.Emote, e.Message, e.StackTrace))); }
/// <summary> /// Appoints a new guild captain to a guild /// </summary> /// <param name="guild">Guild to set the captain for</param> /// <param name="newCaptain">New captain to appoint to the guild</param> /// <param name="oldCaptain">Old captain (can be null)</param> /// <returns>true, if operation succeeds</returns> public static async Task <bool> SetGuildCaptain(MinecraftGuild guild, SocketGuildUser newCaptain, SocketGuildUser oldCaptain) { string errorhint = "Modify channel perms"; try { SocketRole captainRole = newCaptain.Guild.GetRole(SettingsModel.GuildCaptainRole); if (GuildChannelHelper.TryGetChannel(guild.ChannelId, out SocketTextChannel guildChannel)) { if (oldCaptain != null) { await guildChannel.RemovePermissionOverwriteAsync(oldCaptain); } await guildChannel.AddPermissionOverwriteAsync(newCaptain, CaptainChannelPerms); } errorhint = "Modify and save"; if (captainRole != null) { await newCaptain.AddRoleAsync(captainRole); } if (oldCaptain != null) { if (captainRole != null) { await oldCaptain.RemoveRoleAsync(captainRole); } guild.MemberIds.Add(guild.CaptainId); } guild.MemberIds.Remove(newCaptain.Id); guild.MateIds.Remove(newCaptain.Id); guild.CaptainId = newCaptain.Id; await SaveAll(); return(true); } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, $"Error setting captain for {guild.Name} to {newCaptain.Mention}. Hint: {errorhint}"); return(false); } }
/// <summary> /// Deletes a guild both on server and in data /// </summary> /// <param name="minecraftGuild">Guild to remove</param> /// <returns>True, if operation completed</returns> public static async Task <bool> DeleteGuildAsync(SocketGuild discordGuild, MinecraftGuild minecraftGuild) { string errorhint = "Removing Guild Role"; try { SocketRole guildRole = discordGuild.GetRole(minecraftGuild.RoleId); SocketRole captainRole = discordGuild.GetRole(SettingsModel.GuildCaptainRole); if (guildRole != null) { await guildRole.DeleteAsync(); } errorhint = "Removing captain role from captain"; SocketGuildUser captain = discordGuild.GetUser(minecraftGuild.CaptainId); if (captain != null && captainRole != null) { if (captain.Roles.Any(item => { return(item.Id == captainRole.Id); })) { await captain.RemoveRoleAsync(captainRole); } } errorhint = "Removing Guild Channel"; if (GuildChannelHelper.TryGetChannel(minecraftGuild.ChannelId, out SocketTextChannel guildChannel)) { await guildChannel.DeleteAsync(); } errorhint = "Removing Guild and Saving"; await DeleteGuildDatasetAsync(minecraftGuild); errorhint = "Notify Admins"; await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Remove ingame represantation of guild\"{minecraftGuild.Name}\"", string.Empty); return(true); } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, $"Error removing guild {minecraftGuild.Name}. Hint: {errorhint}"); return(false); } }
/// <summary> /// Changes a guilds name /// </summary> /// <param name="guild">Guild to modify</param> /// <param name="newName">New name for the guild</param> /// <returns>true, if operation succeeds</returns> public static async Task <bool> UpdateGuildNameAsync(MinecraftGuild guild, string newName) { string errorhint = "Modifying Guild Channel"; try { if (GuildChannelHelper.TryGetChannel(guild.ChannelId, out SocketTextChannel guildChannel) && BotCore.Client.TryGetRole(guild.RoleId, out SocketRole guildRole)) { await guildChannel.ModifyAsync(GuildChannelProperties => { GuildChannelProperties.Name = newName; GuildChannelProperties.Topic = "Private Guild Channel for " + newName; }); errorhint = "Modifying Guild Role"; await guildRole.ModifyAsync(RoleProperties => { RoleProperties.Name = newName; }); errorhint = "Setting Guild Name"; string oldname = guild.Name; guild.Name = newName; errorhint = "Notify Admins"; await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Rename guild \"{oldname}\" to \"{newName}\" ingame", string.Empty); return(true); } else { return(false); } } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, $"Error renaming guild {guild.Name} to {newName}. Hint: {errorhint}"); return(false); } }
/// <summary> /// Sends a new admin task /// </summary> /// <param name="taskTitle">Title of the task</param> /// <param name="taskDescription">Further information</param> public static async Task <AdminTaskInteractiveMessage> CreateAdminTaskMessage(string taskTitle, string taskDescription) { if (GuildChannelHelper.TryGetChannel(GuildChannelHelper.AdminNotificationChannelId, out SocketTextChannel channel)) { EmbedBuilder embed = new EmbedBuilder() { Title = taskTitle, Description = taskDescription, Color = Red, Footer = Footer }; Discord.Rest.RestUserMessage message = await channel.SendEmbedAsync(embed); AdminTaskInteractiveMessage result = new AdminTaskInteractiveMessage(message as IUserMessage, taskTitle); await message.AddReactionsAsync(new IEmote[] { UnicodeEmoteService.Checkmark, UnicodeEmoteService.Cross }); return(result); } else { return(null); } }
protected override async Task HandleCommandAsync(CommandContext context) { GuildChannelHelper.TryGetChannel(GuildChannelHelper.DebugChannelId, out SocketTextChannel debugChannel); GuildChannelHelper.TryGetChannel(GuildChannelHelper.WelcomingChannelId, out SocketTextChannel welcomingChannel); GuildChannelHelper.TryGetChannel(GuildChannelHelper.AdminCommandUsageLogChannelId, out SocketTextChannel adminCommandUsageLogging); GuildChannelHelper.TryGetChannel(GuildChannelHelper.AdminNotificationChannelId, out SocketTextChannel adminNotificationChannel); GuildChannelHelper.TryGetChannel(GuildChannelHelper.InteractiveMessagesChannelId, out SocketTextChannel interactiveMessagesChannel); SocketRole adminRole = null; SocketRole botNotifications = null; SocketRole minecraftBranch = null; SocketRole mute = null; if (GuildCommandContext.TryConvert(context, out GuildCommandContext guildContext)) { adminRole = guildContext.Guild.GetRole(SettingsModel.AdminRole); botNotifications = guildContext.Guild.GetRole(SettingsModel.BotDevRole); minecraftBranch = guildContext.Guild.GetRole(SettingsModel.MinecraftBranchRole); mute = guildContext.Guild.GetRole(SettingsModel.MuteRole); } EmbedBuilder embed = new EmbedBuilder() { Title = "Current Settings", Color = BotCore.EmbedColor, Description = $"YNB Bot {Var.VERSION}" }; StringBuilder debugLogging = new StringBuilder("Logging Channel: "); if (debugChannel == null) { debugLogging.AppendLine(Markdown.InlineCodeBlock(GuildChannelHelper.DebugChannelId)); } else { debugLogging.AppendLine(debugChannel.Mention); } for (int i = 0; i < SettingsModel.debugLogging.Length; i++) { bool option = SettingsModel.debugLogging[i]; debugLogging.AppendLine($"{(DebugCategories)i}: { (option ? "**enabled**" : "disabled") }"); } embed.AddField("Debug Logging", debugLogging); embed.AddField("Channels", $"Welcoming: { (welcomingChannel == null ? Markdown.InlineCodeBlock(GuildChannelHelper.WelcomingChannelId) : welcomingChannel.Mention) }\n" + $"Interactive Messages: {(interactiveMessagesChannel == null ? Markdown.InlineCodeBlock(GuildChannelHelper.InteractiveMessagesChannelId) : interactiveMessagesChannel.Mention)}\n" + $"Admin Command Usage Logging: {(adminCommandUsageLogging == null ? Markdown.InlineCodeBlock(GuildChannelHelper.AdminCommandUsageLogChannelId) : adminCommandUsageLogging.Mention)}\n" + $"Admin Notifications: {(adminNotificationChannel == null ? Markdown.InlineCodeBlock(GuildChannelHelper.AdminNotificationChannelId) : adminNotificationChannel.Mention)}"); embed.AddField("Roles", $"Admin Role: { (adminRole == null ? Markdown.InlineCodeBlock(SettingsModel.AdminRole) : adminRole.Mention) }\n" + $"Bot Notifications Role: { (botNotifications == null ? Markdown.InlineCodeBlock(SettingsModel.BotDevRole) : botNotifications.Mention) }\n" + $"Minecraft Branch Role: {(minecraftBranch == null ? Markdown.InlineCodeBlock(SettingsModel.MinecraftBranchRole) : minecraftBranch.Mention)}\n" + $"Mute Role: {(mute == null ? Markdown.InlineCodeBlock(SettingsModel.MuteRole) : mute.Mention)}"); string bAdmins = SettingsModel.botAdminIDs.OperationJoin(", ", id => { SocketGuildUser user = null; if (context.IsGuildContext) { user = guildContext.Guild.GetUser(id); } if (user != null) { return($"{user.Mention} (`{user.Id}`)"); } else { return(Markdown.InlineCodeBlock(user.Id.ToString())); } }); embed.AddField($"Bot Admins - {SettingsModel.botAdminIDs.Count}", bAdmins); await context.Channel.SendEmbedAsync(embed); }