internal static void LoadSettings(ulong guildId, BotVar var) { if (var.IsGeneric) { JSONContainer json = var.Generic; if (json.TryGetField(JSON_ENABLEDEBUG, out JSONContainer debugSettings)) { if (debugSettings.IsArray) { for (int i = 0; i < debugSettings.Array.Count && i < debugLogging.Length; i++) { debugLogging[i] = debugSettings.Array[i].Boolean; } } } json.TryGetField(JSON_MODERATORROLE, out AdminRole); json.TryGetField(JSON_WELCOMINGMESSAGE, out welcomingMessage, welcomingMessage); json.TryGetField(JSON_MUTEROLE, out MuteRole); if (json.TryGetField(JSON_CHANNELINFOS, out JSONContainer guildChannelInfoContainer)) { GuildChannelHelper.FromJSON(guildChannelInfoContainer); } if (json.TryGetArrayField(JSON_AUTOASSIGNROLEIDS, out JSONContainer autoAssignRoles)) { foreach (JSONField idField in autoAssignRoles.Array) { if (idField.IsNumber && !idField.IsFloat && !idField.IsSigned) { EventLogger.AutoAssignRoleIds.Add(idField.Unsigned_Int64); } } } } }
/// <summary> /// Sends a message into the Debug Message Channel if it is defined and Debug is true /// </summary> /// <param name="message">Message to send</param> public static async Task SendDebugMessage(DebugCategories category, string message, string description = null) { if (DebugMessage != null) { await DebugMessage(new LogMessage(LogSeverity.Debug, category.ToString(), message)); } if (debugLogging[(int)category] && GuildChannelHelper.TryGetChannel(GuildChannelHelper.DebugChannelId, out SocketTextChannel channel)) { EmbedBuilder debugembed; if (string.IsNullOrEmpty(description)) { debugembed = new EmbedBuilder { Color = BotCore.EmbedColor, Title = $"**[{category.ToString().ToUpper()}]**", Description = message }; } else { debugembed = new EmbedBuilder { Color = BotCore.EmbedColor, Title = $"**[{category.ToString().ToUpper()}]** {message}", Description = description }; } await channel.SendEmbedAsync(debugembed); } }
/// <summary> /// Saves all settings to appdata/locallow/Ciridium Wing Bot/Settings.json /// </summary> internal static void SaveSettings() { JSONContainer json = JSONContainer.NewObject(); JSONContainer debugSettings = JSONContainer.NewArray(); foreach (bool b in debugLogging) { debugSettings.Add(b); } json.TryAddField(JSON_MODERATORROLE, AdminRole); json.TryAddField(JSON_ENABLEDEBUG, debugSettings); json.TryAddField(JSON_WELCOMINGMESSAGE, welcomingMessage); json.TryAddField(JSON_MUTEROLE, MuteRole); json.TryAddField(JSON_CHANNELINFOS, GuildChannelHelper.ToJSON()); JSONContainer autoAssignRoleIds = JSONContainer.NewArray(); foreach (var roleId in EventLogger.AutoAssignRoleIds) { autoAssignRoleIds.Add(roleId); } json.TryAddField(JSON_AUTOASSIGNROLEIDS, autoAssignRoleIds); BotVarManager.GlobalBotVars.SetBotVar("YNBsettings", json); }
/// <summary> /// The method running the timer thread /// </summary> public static async void Run() { while (Var.running) { List <ScheduledCallback> markedForRemoval = new List <ScheduledCallback>(); foreach (ScheduledCallback schedule in scheduledCallbacks) { if (Millis >= schedule.executeAt && schedule.callback != null) { try { await schedule.callback(); } catch (Exception e) { if (schedule.callback != null) { await GuildChannelHelper.SendExceptionNotification(e, $"Error executing callback `{schedule.callback.Method.ToString()}`"); } else { await GuildChannelHelper.SendExceptionNotification(e, $"Error executing callback!"); } } markedForRemoval.Add(schedule); } } lock (scheduledCallbackListLock) { if (markedForRemoval.Count > 0) { foreach (var complete in markedForRemoval) { scheduledCallbacks.Remove(complete); } } lock (newCallbacksLock) { if (newScheduledCallbacks != null) { scheduledCallbacks.AddRange(newScheduledCallbacks); newScheduledCallbacks = null; } } } Thread.Sleep(10); } }
internal static async Task WelcomeNewUser(SocketGuildUser user) { if (GuildChannelHelper.TryGetChannel(GuildChannelHelper.WelcomingChannelId, out SocketTextChannel channel)) { if (user.Guild.Id == channel.Guild.Id) { if (welcomingMessage.Contains("{0}")) { await channel.SendEmbedAsync($"Welcome {user.Mention}!", string.Format(welcomingMessage, user.Mention)); } else { await channel.SendEmbedAsync($"Welcome {user.Mention}!", welcomingMessage); } } } }
public static async Task SendAdminCommandUsedMessage(IDMCommandContext context, Command command) { if (GuildChannelHelper.TryGetChannel(GuildChannelHelper.AdminCommandUsageLogChannelId, out SocketTextChannel channel)) { EmbedBuilder debugembed = new EmbedBuilder { Color = BotCore.EmbedColor, Title = $"Admin-Only command used by {context.User.Username}#{context.User.Discriminator}", }; debugembed.AddField("Command and Arguments", $"Matched Command```{command.Syntax}```Arguments```{context.Message.Content}".MaxLength(1021) + "```"); string location; if (GuildCommandContext.TryConvert(context, out IGuildCommandContext guildContext)) { SocketTextChannel locationChannel = channel.Guild.GetTextChannel(guildContext.Channel.Id); location = $"Guild `{guildContext.Guild.Name}` Channel {(locationChannel == null ? Markdown.InlineCodeBlock(guildContext.Channel.Name) : locationChannel.Mention)}"; } else { location = "Private Message to Bot"; } debugembed.AddField("Location", location); await channel.SendEmbedAsync(debugembed); } }