Ejemplo n.º 1
0
        private async Task MainAsync()
        {
            Settings = JsonConvert.DeserializeObject <BotSettings>(File.ReadAllText(SettingsPath));

            Client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel = LogSeverity.Debug
            });

            Services = new ServiceCollection().BuildServiceProvider();

            using (Database = new LiteDatabase(@"tynibotdata.db")) // DB for long term state
            {
                DefaultHandler = new DefaultHandler(Client, Services);
                ChannelHandlers.Add("recruiting", new Recruiting(Client, Services));

                Client.Log             += Log;
                Client.MessageReceived += MessageReceived;

                await Client.LoginAsync(TokenType.Bot, Settings.BotToken);

                await Client.StartAsync();

                await Task.Delay(-1); // Wait forever
            }
        }
Ejemplo n.º 2
0
        private async Task MainAsync()
        {
            Settings = JsonConvert.DeserializeObject <BotSettings>(File.ReadAllText(SettingsPath));

            Client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel = LogSeverity.Debug
            });

            Services = new ServiceCollection().BuildServiceProvider();

            using (Database = new LiteDatabase(@"tynibotdata.db")) // DB for long term state
            {
                Context = new BotContext(Client, Database, Settings);

                DefaultHandler = new DefaultHandler(Client, Services, new List <Type>());

                var DefaultCommands = new List <Type>()
                {
                    typeof(Ping),
                    typeof(Clear),
                    typeof(Discord.Mafia.MafiaCommand),
                    typeof(Discord.Matches.MatchesCommand),
                    typeof(Discord.Inhouse.InhouseCommand)
                };

                foreach (var type in DefaultCommands)
                {
                    DefaultHandler.Commands.AddModuleAsync(type, Services).Wait();
                }

                // TODO: Dynamically load these from DLLs
                ChannelHandlers.Add("recruiting", new Discord.Recruiting.Recruiting(Client, Services));
                ChannelHandlers.Add("bot-input", new PinMessageHandler(Client, Services, DefaultCommands));
                ChannelHandlers.Add("o365-chat", new PinMessageHandler(Client, Services, DefaultCommands));
                ChannelHandlers.Add("tynibot", new PinMessageHandler(Client, Services, DefaultCommands));

                Client.Log              += Log;
                Client.MessageReceived  += MessageReceived;
                Client.ReactionAdded    += ReactionAddedAsync;
                Client.ReactionRemoved  += ReactionRemovedAsync;
                Client.ReactionsCleared += ReactionsClearedAsync;
                Client.UserJoined       += AnnounceJoinedUser;

                await Client.LoginAsync(TokenType.Bot, Settings.BotToken);

                await Client.StartAsync();

                await Task.Delay(-1); // Wait forever
            }
        }
Ejemplo n.º 3
0
        public async Task RunAsync(
            BotSettings settings,
            Func <LogMessage, Task> logFunction,
            CancellationToken?stoppingToken = null)
        {
            this.Settings = settings;

            Client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                LogLevel = LogSeverity.Debug
            });

            Services = new ServiceCollection().BuildServiceProvider();

            using (Database = new LiteDatabase(@"tynibotdata.db")) // DB for long term state
            {
                Context = new BotContext(Client, Database, this.Settings);

                DefaultHandler = new DefaultHandler(Client, Services, new List <Type>());

                var DefaultCommands = new List <Type>()
                {
                    //typeof(Clear),
                    typeof(Discord.Mafia.MafiaCommand),
                    typeof(Discord.Matches.MatchesCommand),
                    typeof(Discord.Inhouse.InhouseCommand),
                };

                foreach (var type in DefaultCommands)
                {
                    DefaultHandler.Commands.AddModuleAsync(type, Services).Wait();
                }

                // TODO: Dynamically load these from DLLs
                //ChannelHandlers.Add("recruiting", new Discord.Recruiting.Recruiting(Client, Services));

                Client.Log                  += logFunction;
                Client.MessageReceived      += MessageReceived;
                Client.ReactionAdded        += ReactionAddedAsync;
                Client.ReactionRemoved      += ReactionRemovedAsync;
                Client.ReactionsCleared     += ReactionsClearedAsync;
                Client.UserJoined           += AnnounceJoinedUser;
                Client.SlashCommandExecuted += SlashCommandTriggeredAsync;
                Client.Ready                += ReadyAsync;
                await Client.LoginAsync(TokenType.Bot, this.Settings.BotToken);

                await Client.StartAsync();

                // Bootstrap the CEA Data (Otherwise first response will timeout)
                PlayCEAStats.RequestManagement.LeagueManager.Bootstrap();

                if (!stoppingToken.HasValue)
                {
                    await Task.Delay(-1); // Wait forever
                }
                else
                {
                    // Wait until cancellation is requested.
                    while (!stoppingToken.Value.IsCancellationRequested)
                    {
                        await Task.Delay(int.MaxValue, stoppingToken.Value);
                    }
                }
            }
        }