示例#1
0
        public async Task EveryMinuteAsync()
        {
            foreach (var file in Directory.EnumerateFiles("Logs"))
            {
                var age = DateTime.Now.Subtract(File.GetLastWriteTime(file));
                if (age.TotalMinutes < 60)
                {
                    continue;
                }
                var id = int.Parse(Path.GetFileNameWithoutExtension(file));
                if (await DecksiteApi.LogUploadedAsync(id))
                {
                    var destFileName = Path.Combine("Logs", "Archive", id + ".txt");
                    if (File.Exists(destFileName))
                    {
                        Console.WriteLine($"Reuploading {id} to logsite...");
                        File.Delete(destFileName);
                        await DecksiteApi.UploadLogAsync(id);

                        return;
                    }
                    Console.WriteLine($"Archiving log for {id}...");
                    File.Move(file, destFileName);
                    return;
                }
                try
                {
                    Console.WriteLine($"Uploading {id} to logsite...");
                    await DecksiteApi.UploadLogAsync(id);

                    return;
                }
                catch (UriFormatException)
                {
                    // This log is too long.
                    Console.WriteLine($"Upload failed.");
                    var destFileName = Path.Combine("Logs", "Failed", id + ".txt");
                    File.Move(file, destFileName);
                }
            }
        }
示例#2
0
        private static async Task SendLogToChannelAsync(ISocketMessageChannel channel, string id)
        {
            var file = Path.Combine("Logs", id + ".txt");

            if (!File.Exists(file))
            {
                file = Path.Combine("Logs", "Archive", id + ".txt");
            }
            if (!File.Exists(file))
            {
                file = Path.Combine("Logs", "Failed", id + ".txt");
            }

            if (File.Exists(file))
            {
                await channel.TriggerTypingAsync();

                try
                {
                    await DecksiteApi.UploadLogAsync(int.Parse(id));

                    await channel.SendMessageAsync($"https://logs.pennydreadfulmagic.com/match/{id}/");
                }
                catch (Exception e)
                {
                    var contents = File.ReadAllLines(file);
                    var caption  = $"Format={contents[0]}, Comment=\"{contents[1]}\", Players=[{contents[3]}]";
                    await channel.SendFileAsync(file, caption);

                    Console.WriteLine($"Couldn't upload to logsite, {e}");
                }
            }
            else
            {
                await channel.TriggerTypingAsync();

                await channel.SendMessageAsync($"Could not find log for MatchID {id}");
            }
        }