コード例 #1
0
ファイル: Config.cs プロジェクト: Jaika1/MizuiroBot
 public static Config LoadConfig()
 {
     CVTS.WriteLineInfo("Attempting to load program configuration file...");
     if (File.Exists(ConfigDir))
     {
         CVTS.WriteLineInfo($"{Path.GetFileName(ConfigDir)} found, will now attempt to load it.");
         try
         {
             var config = JsonConvert.DeserializeObject <Config>(File.ReadAllText(ConfigDir));
             CVTS.WriteLineOk($"{Path.GetFileName(ConfigDir)} loaded successfully!");
             return(config);
         }
         catch
         {
             CVTS.WriteLineError($"Failed to load {Path.GetFileName(ConfigDir)}! Please check for any errors and restart the application.");
             Console.ReadKey();
             Environment.Exit(0);
         }
     }
     else
     {
         CVTS.WriteLineError($"No config file found! A blank template under the name '{Path.GetFileName(ConfigDir)}' will be made in the application directory.");
         File.WriteAllText(ConfigDir, JsonConvert.SerializeObject(new Config(), Formatting.Indented));
         Console.ReadKey();
         Environment.Exit(0);
     }
     return(null);
 }
コード例 #2
0
ファイル: DiscordBot.cs プロジェクト: Jaika1/MizuiroBot
        private async Task MessageReceived(SocketMessage msg)
        {
            SocketUserMessage umsg = (SocketUserMessage)msg;

            if (msg == null)
            {
                return;
            }

            int argPos = 0;

            if (!umsg.HasCharPrefix(CommandPrefix, ref argPos))
            {
                return;
            }
            if (umsg.Author.IsBot)
            {
                return;
            }
            if (umsg.Author.IsWebhook)
            {
                return;
            }
            if (umsg.Channel is SocketDMChannel)
            {
                return;
            }

            var context = new SocketCommandContext(botUser, umsg);

            IResult commandResult = await commandService.ExecuteAsync(context, argPos, null);

            if (commandResult.Error.HasValue)
            {
                if (commandResult.Error.Value != CommandError.UnknownCommand)
                {
                    CVTS.WriteLineError(commandResult.ErrorReason);
                }
                else
                {
                    SharedBotInfo shared = SharedBotInfo.GetSharedInfo(context.Guild.Id);
                    if (shared != null)
                    {
                        try
                        {
                            CustomTwitchCommandInfo customCommand = shared.CustomCommands.First(x => x.Key.StartsWith(umsg.Content.Remove(0, 1)));
                            await context.Channel.SendMessageAsync(customCommand.Value);
                        }
                        catch { }
                    }
                }
            }
        }
コード例 #3
0
        private static void DownloadSplatoon2Data()
        {
            CVTS.WriteLineInfo($"Downloading repository containing Splatoon 2 data from {s2DataUrl}...");
            try
            {
                string masterZipPath = $"{dataLocation}master.zip";
                webClient.DownloadFile(s2DataUrl, masterZipPath);
                CVTS.WriteLineOk($"Download succeeded, extracting data folder...");
                using (ZipArchive archive = ZipFile.OpenRead(masterZipPath))
                {
                    var result = from currEntry in archive.Entries
                                 where Path.GetDirectoryName(currEntry.FullName).Contains(@"leanny.github.io-master\data")
                                 where !string.IsNullOrEmpty(currEntry.Name)
                                 select currEntry;


                    foreach (ZipArchiveEntry entry in result)
                    {
                        string path = Path.Combine(dataLocation, entry.FullName.Replace(@"leanny.github.io-master/data/", null));
                        CVTS.WriteLineInfo($"Extracting {path}...");
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        entry.ExtractToFile(path);
                    }
                }
                CVTS.WriteLineInfo($"Deleting master archive...");
                File.Delete(masterZipPath);
                CVTS.WriteLineOk($"Deletion successful!");
            }
            catch
            {
                CVTS.WriteLineError($"Download process failed to complete successfully!");
            }
        }