public static string Invite(string ecoChannel) { var plugin = DiscordLink.Obj; DLConfigData config = DLConfig.Data; ServerInfo serverInfo = Networking.NetworkManager.GetServerInfo(); string inviteMessage = config.InviteMessage; if (!inviteMessage.Contains(DLConfig.InviteCommandLinkToken) || string.IsNullOrEmpty(serverInfo.DiscordAddress)) { return("This server is not configured for using the /DiscordInvite command."); } inviteMessage = Regex.Replace(inviteMessage, Regex.Escape(DLConfig.InviteCommandLinkToken), serverInfo.DiscordAddress); string formattedInviteMessage = $"#{(string.IsNullOrEmpty(ecoChannel) ? config.EcoCommandOutputChannel : ecoChannel) } {inviteMessage}"; ChatManager.SendChat(formattedInviteMessage, plugin.EcoUser); return("Invite sent"); }
public void Initialize() { _config = new PluginConfig <DLConfigData>("DiscordLink"); _prevConfig = (DLConfigData)Data.Clone(); Data.PlayerConfigs.CollectionChanged += (obj, args) => { HandleCollectionChanged(args); }; Data.ChatChannelLinks.CollectionChanged += (obj, args) => { HandleCollectionChanged(args); }; Data.ServerInfoChannels.CollectionChanged += (obj, args) => { HandleCollectionChanged(args); }; Data.TradeChannels.CollectionChanged += (obj, args) => { HandleCollectionChanged(args); }; Data.SnippetChannels.CollectionChanged += (obj, args) => { HandleCollectionChanged(args); }; Data.WorkPartyChannels.CollectionChanged += (obj, args) => { HandleCollectionChanged(args); }; Data.PlayerListChannels.CollectionChanged += (obj, args) => { HandleCollectionChanged(args); }; Data.ElectionChannels.CollectionChanged += (obj, args) => { HandleCollectionChanged(args); }; BuildChanneLinkList(); DiscordLink.Obj.OnClientStopped += (obj, args) => { _verifiedLinks.Clear(); // If we were waiting to verify channel links, we need to clear this list or risk false positives }; }
public bool Save() // Returns true if no correction was needed { bool correctionMade = false; // Invite Message if (string.IsNullOrEmpty(Data.EcoBotName)) { Data.EcoBotName = DefaultValues.EcoBotName; correctionMade = true; } // Discord Command Prefix if (Data.DiscordCommandPrefix != _prevConfig.DiscordCommandPrefix) { if (string.IsNullOrEmpty(Data.DiscordCommandPrefix)) { Data.DiscordCommandPrefix = DefaultValues.DiscordCommandPrefix; correctionMade = true; Logger.Info("Command prefix found empty - Resetting to default."); } Logger.Info("Command prefix changed - Restart required to take effect."); } // Channel Links foreach (ChannelLink link in _channelLinks) { if (link.MakeCorrections()) { correctionMade = true; } } // Chatlog toggle if (Data.LogChat && !_prevConfig.LogChat) { Logger.Info("Chatlog enabled"); OnChatlogEnabled?.Invoke(this, EventArgs.Empty); } else if (!Data.LogChat && _prevConfig.LogChat) { Logger.Info("Chatlog disabled"); OnChatlogDisabled?.Invoke(this, EventArgs.Empty); } // Chatlog path if (string.IsNullOrEmpty(Data.ChatlogPath)) { Data.ChatlogPath = DiscordLink.BasePath + "Chatlog.txt"; correctionMade = true; } if (Data.ChatlogPath != _prevConfig.ChatlogPath) { Logger.Info("Chatlog path changed. New path: " + Data.ChatlogPath); OnChatlogPathChanged?.Invoke(this, EventArgs.Empty); } // Eco command channel if (string.IsNullOrEmpty(Data.EcoCommandChannel)) { Data.EcoCommandChannel = DefaultValues.EcoCommandChannel; correctionMade = true; } // Invite Message if (string.IsNullOrEmpty(Data.InviteMessage)) { Data.InviteMessage = DefaultValues.InviteMessage; correctionMade = true; } _config.SaveAsync(); OnConfigSaved?.Invoke(this, EventArgs.Empty); _prevConfig = (DLConfigData)Data.Clone(); return(!correctionMade); }
public bool Save() // Returns true if no correction was needed { bool correctionMade = false; // Eco Bot Name if (string.IsNullOrEmpty(Data.EcoBotName)) { Data.EcoBotName = DefaultValues.EcoBotName; correctionMade = true; } // Discord Command Prefix if (Data.DiscordCommandPrefix != _prevConfig.DiscordCommandPrefix) { if (string.IsNullOrEmpty(Data.DiscordCommandPrefix)) { Data.DiscordCommandPrefix = DefaultValues.DiscordCommandPrefix; correctionMade = true; Logger.Info("Command prefix found empty - Resetting to default."); } Logger.Info("Command prefix changed - Restart required to take effect."); } // Channel Links foreach (ChannelLink link in _channelLinks) { if (link.MakeCorrections()) { correctionMade = true; } } // Chatlog toggle if (Data.LogChat && !_prevConfig.LogChat) { Logger.Info("Chatlog enabled"); OnChatlogEnabled?.Invoke(this, EventArgs.Empty); } else if (!Data.LogChat && _prevConfig.LogChat) { Logger.Info("Chatlog disabled"); OnChatlogDisabled?.Invoke(this, EventArgs.Empty); } // Chatlog path if (string.IsNullOrEmpty(Data.ChatlogPath)) { Data.ChatlogPath = DLConstants.BasePath + "Chatlog.txt"; correctionMade = true; } if (Data.ChatlogPath != _prevConfig.ChatlogPath) { Logger.Info("Chatlog path changed. New path: " + Data.ChatlogPath); OnChatlogPathChanged?.Invoke(this, EventArgs.Empty); } // Eco command channel if (string.IsNullOrEmpty(Data.EcoCommandOutputChannel)) { Data.EcoCommandOutputChannel = DefaultValues.EcoCommandOutputChannel; correctionMade = true; } // Max tracked trades per user if (Data.MaxTrackedTradesPerUser < 0) { Data.MaxTrackedTradesPerUser = DLConfig.DefaultValues.MaxTrackedTradesPerUser; } // Invite Message if (string.IsNullOrEmpty(Data.InviteMessage)) { Data.InviteMessage = DefaultValues.InviteMessage; correctionMade = true; } // Currency channels foreach (CurrencyChannelLink link in Data.CurrencyChannels) { if (link.MaxMintedCount < 0) { link.MaxMintedCount = DefaultValues.MaxMintedCurrencies; correctionMade = true; } if (link.MaxPersonalCount < 0) { link.MaxPersonalCount = DefaultValues.MaxPersonalCurrencies; correctionMade = true; } if (link.MaxTopCurrencyHolderCount < 0 || link.MaxTopCurrencyHolderCount > DLConstants.MAX_TOP_CURRENCY_HOLDER_DISPLAY_LIMIT) { link.MaxTopCurrencyHolderCount = DefaultValues.MaxTopCurrencyHolderCount; correctionMade = true; } } _config.SaveAsync(); OnConfigSaved?.Invoke(this, EventArgs.Empty); _prevConfig = (DLConfigData)Data.Clone(); return(!correctionMade); }