Beispiel #1
0
 public CommandContext(BotContext botContext, SocketUserMessage msg, SocketUser user = null) :
     base(botContext.Client, botContext.Database, botContext.Settings)
 {
     Guild   = (msg.Channel as SocketGuildChannel)?.Guild;
     Channel = msg.Channel;
     User    = user ?? msg.Author;
     Message = msg;
 }
Beispiel #2
0
 public ReactionContext(BotContext botContext, IUserMessage msg)
     : base(botContext.Client, botContext.Database, botContext.Settings)
 {
     Guild   = (msg.Channel as SocketGuildChannel)?.Guild;
     Channel = msg.Channel;
     User    = msg.Author;
     Message = msg;
 }
Beispiel #3
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
            }
        }
Beispiel #4
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);
                    }
                }
            }
        }