Exemple #1
0
        //public System.Net.Http.HttpC

        #region Initialization
        public Koala(BotConfig config)
        {
            Bot                = this;
            this.Logger        = new Logger("BOT", null);
            this.Configuration = config;

            //Configure redis
            Logger.Log("Creating new Stack Exchange Client");
            this.Redis = new StackExchangeClient(config.Redis.Address, config.Redis.Database, Logger.CreateChild("REDIS"));
            Namespace.SetRoot(config.Redis.Prefix);
            GuildSettings.DefaultPrefix = config.Prefix;

            Logger.Log("Creating new Database Client");
            this.DbContext = new DbContext(config.SQL, logger: Logger.CreateChild("DB"));

            Logger.Log("Creating Starwatch Client");
            this.Starwatch = new StarwatchClient(config.Starwatch.Host, config.Starwatch.Username, config.Starwatch.Password);

            //Configure Discord
            Logger.Log("Creating new Bot Configuration");
            this.Discord = new DiscordClient(new DiscordConfiguration()
            {
                Token = config.Token
            });

            //Make sure the user isn't updating to bypass moderative actions
            Logger.Log("Creating Instances....");
            ModerationManager = new ModerationManager(this);
            PermissionManager = new PermissionManager(this, Logger.CreateChild("PERM"));
            ReplyManager      = new ReplyManager(this, Logger.CreateChild("REPLY"));
            ReactRoleManager  = new ReactRoleManager(this, Logger.CreateChild("ROLE"));
            TickerManager     = new TickerManager(this, Logger.CreateChild("TICKER"))
            {
                Interval = 120 * 1000
            };
            TickerManager.RegisterTickers(new ITickable[]
            {
                new TickerStarwatch(Starwatch),
                new TickerMessageCount(),
                new TickerStarwatch(Starwatch),
                new TickerRandom(),
            });

            //Track how many messages are sent
            Logger.Log("Creating Message Counter");
            this.MessageCounter = new MessageCounter(this, config.MessageCounterSyncRate * 1000);

            //Setup some deps
            Logger.Log("Creating Dependencies & Registering Commands");
            var deps = new ServiceCollection()
                       .AddSingleton(this)
                       .BuildServiceProvider(true);

            this.CommandsNext = this.Discord.UseCommandsNext(new CommandsNextConfiguration()
            {
                PrefixResolver = ResolvePrefix, Services = deps
            });
            this.CommandsNext.RegisterConverter(new PermissionArgumentConverter());
            this.CommandsNext.RegisterConverter(new MemberPermissionArgumentConverter());
            this.CommandsNext.RegisterConverter(new QueryConverter());
            this.CommandsNext.RegisterConverter(new CommandQueryArgumentConverter());
            this.CommandsNext.RegisterConverter(new Starwatch.CommandNext.WorldConverter(this));

            var curr = Assembly.GetExecutingAssembly();
            var part = Assembly.GetAssembly(typeof(Modules.Starwatch.StarwatchModule.ProtectionModule));

            this.CommandsNext.RegisterCommands(part);
            this.CommandsNext.CommandExecuted += HandleCommandExecuteAsync;

            Logger.Log("Creating Interactivity");
            this.Interactivity = this.Discord.UseInteractivity(new InteractivityConfiguration()
            {
                PaginationBehaviour = DSharpPlus.Interactivity.Enums.PaginationBehaviour.Ignore,
                PaginationDeletion  = DSharpPlus.Interactivity.Enums.PaginationDeletion.DeleteEmojis
            });

            //Catch when any errors occur in the command handler
            //Send any command errors back after logging it.
            Logger.Log("Registering Error Listeners");
            this.Discord.ClientErrored += async(error) => await LogException(error.Exception);

            this.CommandsNext.CommandErrored += HandleCommandErrorAsync;

            Logger.Log("Done");
        }
Exemple #2
0
 public TickerStarwatch(StarwatchClient client)
 {
     this.Client = client;
 }