/// <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); } }
/// <summary> /// Adds a member to a guild /// </summary> /// <param name="guild">Guild the new member joins</param> /// <param name="newMember">New member that joins the guild</param> /// <returns>true, if operation succeeds</returns> public static async Task <bool> MemberJoinGuildAsync(MinecraftGuild guild, SocketGuildUser newMember) { string errorhint = "Adding Guild Role"; try { if (BotCore.Client.TryGetRole(guild.RoleId, out SocketRole guildRole) && !guild.MemberIds.Contains(newMember.Id)) { await newMember.AddRoleAsync(guildRole); errorhint = "Adding Member to Guild and Saving"; guild.MemberIds.Add(newMember.Id); await SaveAll(); errorhint = "Notify Admins"; await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Add user \"{newMember}\" to guild \"{guild.Name}\" ingame", "Joining User: "******"Error joining player {newMember?.Mention} to guild {guild?.Name}. Hint: {errorhint}"); return(false); } }
public static async Task <GuildCreationInteractiveMessage> FromNewGuildAndMemberList(MinecraftGuild guild, List <SocketGuildUser> Members) { StringBuilder mentionString = new StringBuilder(); foreach (SocketGuildUser member in Members) { guild.MemberIds.Add(member.Id); mentionString.Append(member.Mention); mentionString.Append(" "); } RestUserMessage message = await GuildChannelHelper.SendMessage(GuildChannelHelper.InteractiveMessagesChannelId, guild.DiscordColor, content : $"{mentionString}Please confirm ({UnicodeEmoteService.Checkmark}) or deny ({UnicodeEmoteService.Cross}) founding Membership in Guild `{guild.Name}` by reacting to this message! {Markdown.Mention_Role(SettingsModel.AdminRole)} Please choose to confirm ({UnicodeEmoteService.Checkmark}) or deny ({UnicodeEmoteService.Cross}) founding of this guild!", embedTitle : "Setting up Interactive Message - Stand By"); if (message != null) { GuildCreationInteractiveMessage result = new GuildCreationInteractiveMessage(message as IUserMessage, guild); await message.AddReactionsAsync(new IEmote[] { UnicodeEmoteService.Checkmark, UnicodeEmoteService.Cross }); await result.UpdateMessage(message as IUserMessage, Members[0].Guild); 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> /// Changes a guilds color /// </summary> /// <param name="guild">Guild to update</param> /// <param name="newColor">New color to apply</param> /// <returns>true, if operation succeeds</returns> public static async Task <bool> UpdateGuildColorAsync(MinecraftGuild guild, GuildColor newColor) { string errorhint = "Modifying Guild Role"; try { if (BotCore.Client.TryGetRole(guild.RoleId, out SocketRole guildRole)) { await guildRole.ModifyAsync(RoleProperties => { RoleProperties.Color = MinecraftGuild.ToDiscordColor(newColor); }); errorhint = "Setting Guild Color"; guild.Color = newColor; errorhint = "Notify Admins"; await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Change color of guild \"{guild.Name}\" to \"{newColor}\" ingame", $"Color: `{ newColor}` (`0x{ ((uint)newColor).ToString("X")}`)"); return(true); } else { return(false); } } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, $"Error recoloring guild {guild.Name} to {newColor}. Hint: {errorhint}"); return(false); } }
protected override async Task HandleCommandGuildAsync(GuildCommandContext context) { bool foundExisting = GuildChannelHelper.TryGetChannelConfig(Channel.Id, out GuildChannelConfiguration channelConfig); if (!foundExisting) { channelConfig = new GuildChannelConfiguration(Channel.Id); } foreach (var config in Configs) { switch (config.Item1) { case ConfigIdentifier.allowshitposting: channelConfig.AllowShitposting = config.Item2; break; case ConfigIdentifier.allowcommands: channelConfig.AllowCommands = config.Item2; break; } } GuildChannelHelper.SetChannelConfig(channelConfig); await SettingsModel.SaveSettings(); EmbedBuilder embed = new EmbedBuilder() { Color = BotCore.EmbedColor, Description = channelConfig.ToString() }; if (Configs.Count > 0) { embed.Title = $"Configuration applied for channel {Channel.Name}"; } else { embed.Title = $"Configuration of channel {Channel.Name}"; } await context.Channel.SendEmbedAsync(embed); }
/// <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); } }
public static async Task <bool> DemoteGuildMember(MinecraftGuild guild, SocketGuildUser newMate) { try { guild.MateIds.RemoveAll((ulong Id) => { return(Id == newMate.Id); }); guild.MemberIds.Add(newMate.Id); await SaveAll(); return(true); } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, $"Error promoting {newMate.Mention} to mate rank in guild \"{guild.Name}\"."); 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> /// Handles the action /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task HandleAction(MessageInteractionContext context) { try { if (InteractiveMessageService.HasInteractiveMessage(MessageId)) { if (InvalidateMessage) { InteractiveMessageService.RemoveInteractiveMessage(MessageId); } if (await Action(context)) { InteractiveMessageService.RemoveInteractiveMessage(MessageId); } } } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, $"Error handling EmoteInteraction, MessageId `{MessageId}`, Emote {Emote.Name}"); } }
/// <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> /// Removes a member from a guild /// </summary> /// <param name="guild">Guild the member leaves</param> /// <param name="leavingMember">Member that leaves</param> /// <returns>true, if operation succeeds</returns> public static async Task <bool> MemberLeaveGuildAsync(MinecraftGuild guild, SocketGuildUser leavingMember) { string errorhint = "Removing Guild Role"; try { if (guild.MemberIds.Contains(leavingMember.Id) || guild.MateIds.Contains(leavingMember.Id)) { foreach (SocketRole role in leavingMember.Roles) { if (role.Id == guild.RoleId) { await leavingMember.RemoveRoleAsync(role); break; } } errorhint = "Removing Member from Guild and Saving"; guild.MemberIds.Remove(leavingMember.Id); guild.MateIds.Remove(leavingMember.Id); await SaveAll(); errorhint = "Notify Admins"; await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Remove user \"{leavingMember}\" from guild \"{guild.Name}\" ingame", "Leaving User: "******"Error leaving player {leavingMember?.Mention} from guild {guild.Name}. 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); } }
private async void Run() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; while (!closeThreadAfterWork) { if (Task != null) { if (Task.TaskState == WorkerTaskState.Ready) { State = ThreadState.Working; try { await Task.Run(); } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, "A WorkerTask has crashed"); Task = null; } State = ThreadState.Idle; } else { Task = null; } } else if (WorkerThreadService.HasQueuedTask) { Task = WorkerThreadService.DeQueue(); } else { Thread.Sleep(1); } } }
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); }
public static async Task <bool> SetGuildActive(SocketGuild discordGuild, MinecraftGuild minecraftGuild, bool active) { string errorhint = string.Empty; try { List <ulong> MemberIds = new List <ulong>(); MemberIds.Add(minecraftGuild.CaptainId); MemberIds.AddRange(minecraftGuild.MateIds); MemberIds.AddRange(minecraftGuild.MemberIds); SocketRole guildRole = discordGuild.GetRole(minecraftGuild.RoleId); SocketGuildUser captain = discordGuild.GetUser(minecraftGuild.CaptainId); SocketRole captainRole = discordGuild.GetRole(SettingsModel.GuildCaptainRole); if (active) { errorhint = "Adding guild role to members"; if (guildRole != null) { foreach (ulong memberId in MemberIds) { SocketGuildUser member = discordGuild.GetUser(memberId); if (member != null && !member.Roles.Any((role) => { return(role.Id == guildRole.Id); })) { await member.AddRoleAsync(guildRole); } } } errorhint = "Adding Captain Role to Captain"; if (captain != null && captainRole != null) { if (!captain.Roles.Any((role) => { return(role.Id == captainRole.Id); })) { await captain.AddRoleAsync(captainRole); } } } else { errorhint = "Removing guild role from members"; if (guildRole != null) { foreach (ulong memberId in MemberIds) { SocketGuildUser member = discordGuild.GetUser(memberId); if (member != null && member.Roles.Any((role) => { return(role.Id == guildRole.Id); })) { await member.RemoveRoleAsync(guildRole); } } } errorhint = "Removing Captain Role from Captain"; if (captain != null && captainRole != null) { if (captain.Roles.Any((role) => { return(role.Id == captainRole.Id); })) { await captain.RemoveRoleAsync(captainRole); } } } errorhint = "Updating Dataset"; minecraftGuild.Active = active; await SaveAll(); return(true); } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, $"Error setting guild \"{minecraftGuild.Name}\" {(active ? "active" : "inactive")}. Errorhint: {errorhint}"); return(false); } }
/// <summary> /// Creates a new guild (includes role, channel, etc) /// </summary> /// <param name="guild">Discord Server Guild to create channel and role on</param> /// <param name="name">Guild Name</param> /// <param name="color">Guild Display Color</param> /// <param name="captain">Guild Captain</param> /// <param name="members">Guild Users</param> /// <returns>true, if operation succeeds</returns> public static async Task <bool> CreateGuildAsync(SocketGuild guild, string name, GuildColor color, SocketGuildUser captain, List <SocketGuildUser> members) { string errorhint = "Failed a precheck"; try { if (TryGetGuildOfUser(captain.Id, out MinecraftGuild existingCaptainGuild)) { if (existingCaptainGuild.Active || captain.Id == existingCaptainGuild.CaptainId) { errorhint = "Precheck failed on " + captain.Mention; return(false); } else { existingCaptainGuild.MateIds.Remove(captain.Id); existingCaptainGuild.MemberIds.Remove(captain.Id); } } foreach (SocketGuildUser member in members) { if (TryGetGuildOfUser(member.Id, out MinecraftGuild existingMemberGuild)) { if (existingCaptainGuild.Active || member.Id == existingCaptainGuild.CaptainId) { return(false); } else { errorhint = "Precheck failed on " + member.Mention; existingCaptainGuild.MateIds.Remove(member.Id); existingCaptainGuild.MemberIds.Remove(member.Id); } } } errorhint = "Failed to create Guild Role!"; RestRole guildRole = await guild.CreateRoleAsync(name, color : MinecraftGuild.ToDiscordColor(color), isHoisted : true); errorhint = "Move role into position"; await guildRole.ModifyAsync(RoleProperties => { RoleProperties.Position = GUILD_ROLE_POSITION; }); errorhint = "Failed to create Guild Channel!"; SocketCategoryChannel guildCategory = guild.GetChannel(GuildChannelHelper.GuildCategoryId) as SocketCategoryChannel; if (guildCategory == null) { throw new Exception("Could not find Guild Category Channel!"); } RestTextChannel guildChannel = await guild.CreateTextChannelAsync(name, TextChannelProperties => { TextChannelProperties.CategoryId = GuildChannelHelper.GuildCategoryId; TextChannelProperties.Topic = "Private Guild Channel for " + name; }); errorhint = "Failed to copy guildcategories permissions"; foreach (Overwrite overwrite in guildCategory.PermissionOverwrites) { IRole role = guild.GetRole(overwrite.TargetId); if (role != null) { await guildChannel.AddPermissionOverwriteAsync(role, overwrite.Permissions); } } errorhint = "Failed to set Guild Channel Permissions!"; await guildChannel.AddPermissionOverwriteAsync(guildRole, GuildRoleChannelPerms); await guildChannel.AddPermissionOverwriteAsync(captain, CaptainChannelPerms); errorhint = "Failed to add Guild Role to Captain!"; await captain.AddRoleAsync(guildRole); errorhint = "Failed to add GuildCaptain Role to Captain!"; SocketRole captainRole = guild.GetRole(SettingsModel.GuildCaptainRole); if (captainRole != null) { await captain.AddRoleAsync(captainRole); } errorhint = "Failed to add Guild Role to a Member!"; foreach (SocketGuildUser member in members) { await member.AddRoleAsync(guildRole); } errorhint = "Failed to create MinecraftGuild!"; StringBuilder memberPingString = new StringBuilder(); MinecraftGuild minecraftGuild = new MinecraftGuild(guildChannel.Id, guildRole.Id, color, name, captain.Id); for (int i = 0; i < members.Count; i++) { SocketGuildUser member = members[i]; minecraftGuild.MemberIds.Add(member.Id); memberPingString.Append(member.Mention); if (i < members.Count - 1) { memberPingString.Append(", "); } } guilds.Add(minecraftGuild); errorhint = "Failed to save MinecraftGuild!"; await SaveAll(); errorhint = "Failed to send or pin guild info embed"; var infomessage = await guildChannel.SendMessageAsync(embed : GuildHelpEmbed.Build()); await infomessage.PinAsync(); errorhint = "Notify Admins"; await AdminTaskInteractiveMessage.CreateAdminTaskMessage($"Create ingame represantation for guild \"{name}\"", $"Name: `{name}`, Color: `{color}` (`0x{((uint)color).ToString("X")}`)\nCaptain: {captain.Mention}\nMembers: {memberPingString}"); return(true); } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, $"Error creating guild {name}. Hint: {errorhint}"); return(false); } }
private static async void CheckTimeLimitedInfractions() { TimeSpan waitDelay = TimeSpan.FromMinutes(1); Thread.Sleep(waitDelay); while (true) { foreach (UserModerationLog userModlog in timeLimitedInfractions) { try { if (userModlog.IsBanned) { if (userModlog.BannedUntil.Value < DateTimeOffset.UtcNow) { // Unban User await UnbanUser(userModlog); lock (removelistlock) { toBeRemoved.Add(userModlog); } } } else if (userModlog.IsMuted) { if (userModlog.MutedUntil.Value < DateTimeOffset.UtcNow) { // Unmute User await UnMuteUser(userModlog); lock (removelistlock) { toBeRemoved.Add(userModlog); } } } else { lock (removelistlock) { toBeRemoved.Add(userModlog); } } } catch (Exception e) { await GuildChannelHelper.SendExceptionNotification(e, string.Empty); } } lock (removelistlock) { timeLimitedInfractions.RemoveRange(toBeRemoved); toBeRemoved.Clear(); } lock (addlistlock) { timeLimitedInfractions.AddRange(toBeAdded); toBeAdded.Clear(); } Thread.Sleep(waitDelay); } }