예제 #1
0
        public Plugin(CommandManager command)
        {
            this.Config = (Configuration)this.Interface.GetPluginConfig() ?? new Configuration();
            this.Config.Initialize(this.Interface);


            this.DiscordBridgeProvider = new DiscordBridgeProvider(this.Interface, new DiscordBridgeAPI(this));
            this.Discord = new DiscordHandler(this);
            // Task t = this.Discord.Start(); // bot won't start if we just have this

            Task.Run(async() =>  // makes the bot actually start
            {
                await this.Discord.Start();
            });


            this.ui = new PluginUI(this);
            this.Interface.UiBuilder.Draw += this.ui.Draw;

            this.Chat.ChatMessage += ChatOnOnChatMessage;
            this.State.CfPop      += ClientStateOnCfPop;

            this.commandManager = new PluginCommandManager <Plugin>(this, command);

            if (string.IsNullOrEmpty(this.Config.DiscordToken))
            {
                this.Chat.PrintError("The Discord Bridge plugin was installed successfully." +
                                     "Please use the \"/pdiscord\" command to set it up.");
            }
        }
예제 #2
0
        public Plugin(CommandManager command)
        {
            this.Config = (Configuration)this.Interface.GetPluginConfig() ?? new Configuration();
            this.Config.Initialize(this.Interface);

            // sanity check - ensure there are no invalid types leftover from past versions.
            foreach (DiscordChannelConfig config in this.Config.ChannelConfigs.Values)
            {
                for (int i = 0; i < config.ChatTypes.Count; i++)
                {
                    XivChatType xct = config.ChatTypes[i];
                    if ((int)xct > 127)
                    {
                        config.ChatTypes[i] = (XivChatType)((int)xct & 0x7F);
                        this.Config.Save();
                    }
                    try
                    {
                        xct.GetInfo();
                    }
                    catch (ArgumentException)
                    {
                        PluginLog.Error($"Removing invalid chat type before it could cause problems ({(int)xct}){xct}.");
                        config.ChatTypes.RemoveAt(i--);
                        this.Config.Save();
                    }
                }
            }


            this.DiscordBridgeProvider = new DiscordBridgeProvider(this.Interface, new DiscordBridgeAPI(this));
            this.Discord = new DiscordHandler(this);
            // Task t = this.Discord.Start(); // bot won't start if we just have this

            Task.Run(async() =>  // makes the bot actually start
            {
                await this.Discord.Start();
            });


            this.ui = new PluginUI(this);
            this.Interface.UiBuilder.Draw += this.ui.Draw;

            this.Chat.ChatMessage += ChatOnOnChatMessage;
            this.State.CfPop      += ClientStateOnCfPop;

            this.commandManager = new PluginCommandManager <Plugin>(this, command);

            if (string.IsNullOrEmpty(this.Config.DiscordToken))
            {
                this.Chat.PrintError("The Discord Bridge plugin was installed successfully." +
                                     "Please use the \"/pdiscord\" command to set it up.");
            }
        }