コード例 #1
0
ファイル: Program.cs プロジェクト: Xwilarg/SkytaleBot
        private async Task MainAsync()
        {
            await BotDb.InitAsync("SkytaleBot");

            client.MessageReceived += HandleCommandAsync;
            client.Connected       += Connected;
            client.GuildAvailable  += GuildUpdate;
            client.JoinedGuild     += GuildUpdate;
            client.ReactionAdded   += ReactionAdded;

            await commands.AddModuleAsync <Modules.Settings>(null);

            await commands.AddModuleAsync <Modules.Information>(null);

            await commands.AddModuleAsync <Modules.Moderation>(null);

            await commands.AddModuleAsync <Modules.Leveling>(null);

            if (!File.Exists("Keys/Credentials.json"))
            {
                throw new FileNotFoundException("You must have a Credentials.json located in a 'Keys' folder near your executable.\nIt must contains a KeyValue botToken containing the token of your bot");
            }
            dynamic json = JsonConvert.DeserializeObject(File.ReadAllText("Keys/Credentials.json"));

            if (json.botToken == null)
            {
                throw new FileNotFoundException("You must have a Credentials.json located in a 'Keys' folder near your executable.\nIt must contains a KeyValue botToken containing the token of your bot");
            }
            if (json.websiteUrl != null && json.websiteToken != null)
            {
                websiteCredentials = new Tuple <string, string>((string)json.websiteUrl, (string)json.websiteToken);
            }
            else
            {
                websiteCredentials = null;
            }
            PerspectiveApi = json.perspectiveToken;
            if (json.googleAPIJson != null)
            {
                TClient = TranslationClient.Create(GoogleCredential.FromFile((string)json.googleAPIJson));
            }
            else
            {
                TClient = null;
            }

            await client.LoginAsync(TokenType.Bot, (string)json.botToken);

            StartTime = DateTime.Now;
            await client.StartAsync();

            await Task.Delay(-1);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Xwilarg/Tsugumi
        private async Task MainAsync()
        {
            await BotDb.InitAsync("Tsugumi");

            client.MessageReceived += HandleCommandAsync;

            await commands.AddModuleAsync <CommunicationModule>(null);

            await commands.AddModuleAsync <FateGOModule>(null);

            if (!File.Exists("Keys/token.txt"))
            {
                throw new FileNotFoundException("Missing token.txt in Keys/");
            }
            await client.LoginAsync(TokenType.Bot, File.ReadAllText("Keys/token.txt"));

            StartTime = DateTime.Now;
            await client.StartAsync();

            await Task.Delay(-1);
        }