예제 #1
0
        private void MainNoStatic()
        {
            CreateFiles();
            ConfigFileManager.LoadConfigFiles(MainApp);

            /*var test = Settings.Database ?? new Dictionary<string, string>();
             * test.Add("test", "tast");*/
            Settings.SaveConfig();
        }
예제 #2
0
        private static async Task Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;

            MainInstance = new DiscordBot();

            ConfigFileManager.LoadConfigFiles(MainInstance);
            MainInstance.Client = new DiscordSocketClient();
            MainInstance.Random = new Random();

            MainInstance.DataProvider = new LiteDatabase("data.db");
            EmojiHelper.Initialize("Config/emoji.tsv", MainInstance.Random);

            MainInstance.Client.Log           += MainInstance.Log;
            MainInstance.Client.Ready         += MainInstance.Client_Ready;
            MainInstance.Client.ReactionAdded += MainInstance.Client_ReactionAdded;

            MainInstance.Clerk = new Clerk();

            await MainInstance.Client.LoginAsync(TokenType.Bot, MainInstance.Secret.Token);

            await MainInstance.Client.StartAsync();

            var ch = new CommandHandler(
                MainInstance.Client,
                new CommandService(
                    new CommandServiceConfig()
            {
                CaseSensitiveCommands = false,
                LogLevel = LogSeverity.Info
            }
                    ),
                MainInstance
                );

            await ch.InstallCommandsAsync();

            await Task.Delay(-1);
        }
예제 #3
0
        public static async Task Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;

            MainInstance = new DiscordBot();
            MainInstance.SetupServices();

            ConfigFileManager.LoadConfigFiles(MainInstance);
            MainInstance.Client = new DiscordSocketClient();

            var eventWrapper = new AsyncEventExecutor();

            eventWrapper.TaskFaulted            += MainInstance.EventWrapper_TaskFaulted;
            MainInstance.Client.Log             += MainInstance.Log;
            MainInstance.Client.Ready           += MainInstance.Client_Ready;
            MainInstance.Client.ReactionAdded   += eventWrapper.CreateEventHandler <Cacheable <IUserMessage, ulong>, ISocketMessageChannel, SocketReaction>(MainInstance.Client_ReactionAdded);
            MainInstance.Client.MessageReceived += eventWrapper.CreateEventHandler <SocketMessage>(MainInstance.Client_MessageReceived);

            if (MainInstance.Secret?.Token is null)
            {
                throw new ArgumentNullException("Token", "Please specify a token in the secret.json file");
            }

            await MainInstance.Client.LoginAsync(TokenType.Bot, MainInstance.Secret.Token);

            await MainInstance.Client.StartAsync();

            var ch = new CommandHandler(
                MainInstance.Client,
                MainInstance
                );

            await ch.InstallCommandsAsync();

            await Task.Delay(-1);
        }
예제 #4
0
        private async Task MainAsync()
        {
            CommandRunner.LoadCommands();
            CreateFiles();

            //BotSettings settings = Config.LoadConfig<BotSettings>("settings.json");
            //ChannelDescriptions descriptions = Config.LoadConfig<ChannelDescriptions>("descriptions.json");
            //UserStatuses s = Config.LoadConfig<UserStatuses>("statuses.json");

            Client     = new DiscordSocketClient();
            RestClient = new DiscordRestClient();
            Grammar    = new GrammarPolice(this);

            ConfigFileManager.LoadConfigFiles(this);

            DefaultTimeZone = Settings.Timezone ?? "UTC";

            Client.Log                += Log;
            Client.MessageReceived    += Client_MessageReceived;
            Client.Ready              += Client_Ready;
            Client.GuildMemberUpdated += Client_GuildMemberUpdated;
            Client.ReactionAdded      += Client_ReactionAdded;

            if (Settings.Token == null)
            {
                throw new KeyNotFoundException("Token not found in settings file");
            }
            await Client.LoginAsync(TokenType.Bot, Settings.Token);

            await Client.StartAsync();

            await RestClient.LoginAsync(TokenType.Bot, Settings.Token);

            // Block this task until the program is closed.
            await Task.Delay(-1);
        }