Example #1
0
        public static void Main(string[] args)
        {
            if (Environment.UserInteractive)
            {
                IrcBot bot;

                if (args.Length > 0)
                {
                    switch (args[0])
                    {
                        case "--install":
                            ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
                            return;
                        case "--uninstall":
                            ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
                            return;
                        case "--simulator":

                            break;
                        case "--config":
                            Tool.Configure();
                            return;
                        case "--help":
                            return;
                        case "--plugin-command":
                            bot = new IrcBot();
                            var manager = new BotPluginManager(bot, "plugins");
                            manager.StartUp();
                            bot.CallExportedCommand(args[1], string.Concat(args.Skip(2)), manager);
                            manager.ShutDown();
                            return;
                    }
                }
                Tool.RunOnMono();

                do
                {
                    bot = GetBot();

                    if (bot == null)
                    {
                        break;
                    }

                } while (bot.Start());

                Settings.Default.Save();
            }
            else
            {

                try
                {
                    var servicesToRun = new ServiceBase[] { new ServiceEngine { Bot = GetBot() } };
                    ServiceBase.Run(servicesToRun);
                }
                catch (Exception exception)
                {
                    Log.Instance.Log(exception);
                }
            }
        }
Example #2
0
 static void PlugManagerPluginLoadEvent(object sender, BotPluginManager.PluginLoadEventArgs e)
 {
     switch (e.EventType)
     {
         case BotPluginManager.PluginLoadEventType.Failed:
             Log.Instance.Log(" [FAILED] " + e.PluginName + " (Init failed)", Level.Info, ConsoleColor.Red);
             break;
         case BotPluginManager.PluginLoadEventType.Reload:
             Log.Instance.Log(" [RELOAD] " + e.PluginName, Level.Info, ConsoleColor.DarkGreen);
             break;
         case BotPluginManager.PluginLoadEventType.Update:
             Log.Instance.Log(" [UPDATE] " + e.PluginName, Level.Info, ConsoleColor.DarkGreen);
             break;
         case BotPluginManager.PluginLoadEventType.Load:
             Log.Instance.Log("  [LOAD]  " + e.PluginName, Level.Info, ConsoleColor.Green);
             break;
         case BotPluginManager.PluginLoadEventType.Remove:
             Log.Instance.Log(" [REMOVE] " + e.PluginName, Level.Info, ConsoleColor.Red);
             break;
     }
 }
Example #3
0
        private void SetupOnce()
        {
            if (isSetup) return;
            isSetup = true;

            MainBotData = new Main(DatabaseConnection.Create("Huffelpuff"));

            if (MainBotData.Channels.Count() == 0 && !Settings.Default.Channel.IsNullOrEmpty())
            {
                foreach (var channelName in Settings.Default.Channel.Split(','))
                {
                    var channel = new Channel { ChannelName = channelName };
                    MainBotData.Channels.InsertOnSubmit(channel);
                }
            }
            MainBotData.SubmitChanges();

            Encoding = System.Text.Encoding.UTF8;
            SendDelay = 3000;
            PingInterval = 120;
            ActiveChannelSyncing = true;
            OnRawMessage += RawMessageHandler;
            AutoRejoin = true;
            AutoRetry = true;
            AutoRetryDelay = 5;
            SupportNonRfc = true;
            OnChannelMessage += CommandDispatcher;
            OnQueryMessage += CommandDispatcher;
            OnConnected += OnBotConnected;

            CtcpVersion = VersionString + " (SharpIRC " + Assembly.GetAssembly(typeof(IrcFeatures)).GetName(false).Version + ")";
            CtcpUrl = "https://github.com/FreeApophis/huffelpuff-irc-bot";
            CtcpSource = "https://github.com/FreeApophis/huffelpuff-irc-bot";

            // DCC Setup

            /* todo: find NAT / or our IP / sharp-IRC should be able to do that -> implement there */

            //Setting up Access Control
            Acl = new AccessControlList(this);
            Acl.Init();

            // Add Identify Plugin suitable (or all)
            Acl.AddIdentifyPlugin(new NickServIdentify(this));
            Acl.AddIdentifyPlugin(new HostIdentify(this));
            Acl.AddIdentifyPlugin(new PasswordIdentify(this));
            Acl.AddIdentifyPlugin(new NickIdentify(this));

            // Plugin needs the Handlers from IRC we load the plugins after we set everything up
            PlugManager = new BotPluginManager(this, "plugins");
            PlugManager.PluginLoadEvent += PlugManagerPluginLoadEvent;
            PlugManager.StartUp();

            //Basic Commands
            AddCommand(new Commandlet("!join", "The command !join <channel> lets the bot join Channel <channel>", JoinCommand, this, CommandScope.Both, "engine_join"));
            AddCommand(new Commandlet("!part", "The command !part <channel> lets the bot part Channel <channel>", PartCommand, this, CommandScope.Both, "engine_part"));
            AddCommand(new Commandlet("!channels", "The command !channels lists all channels where the bot resides", ListChannelCommand, this));
            AddCommand(new Commandlet("!quit", "The command !quit lets the bot quit himself", QuitCommand, this, CommandScope.Both, "engine_quit"));

            //Plugin Commands
            AddCommand(new Commandlet("!plugins", "The command !plugins lists all the plugins", PluginsCommand, this));
            AddCommand(new Commandlet("!activate", "The command !activate <plugin> activates the Plugin <plugin>", ActivateCommand, this, CommandScope.Both, "engine_activate"));
            AddCommand(new Commandlet("!deactivate", "The command !deactivate <plugin> deactivates the Plugin <plugin>", DeactivateCommand, this, CommandScope.Both, "engine_deactivate"));

            //Helper Commands (!commands)
            AddCommand(new Commandlet("!help", "The command !help <topic> gives you help about <topic> (special topics: commands, more)", HelpCommand, this));

            //Settings Commands
            new SettingCommands(this);
        }
Example #4
0
        public void CallExportedCommand(string command, string parameter = null, BotPluginManager pluginManager = null, object sender = null)
        {
            var botPluginManager = pluginManager ?? PlugManager;

            if (!exported.ContainsKey(command)) { return; }

            var e = new CommandEventArgs(parameter);

            foreach (var plug in botPluginManager.Plugins.Where(plug => plug.FullName == (string)exported[command].Owner))
            {
                plug.InvokeHandler(exported[command].HandlerName, e);
                return;
            }
        }