public async Task CaptchaAsync() { DirectoryInfo dir = new DirectoryInfo(CaptchaPath); FileInfo[] Files = dir.GetFiles("*.png"); int index = Rand.Next(Files.Length); var message = await Context.Channel.SendFileAsync(Files[index].FullName, "Reply with text in Image."); var captchaState = new CaptchaState(message, Path.GetFileNameWithoutExtension(Files[index].Name)); CaptchaService.AddCaptcha(captchaState); }
private string GetResponse(string id) { while (true) { CaptchaState state = Check(id); if (state == CaptchaState.Success) { return(captcha); } else if (state == CaptchaState.NotReady) { Thread.Sleep(interval); } else if (state == CaptchaState.NoFreeWorker) { throw new NoFreeWorkerException(); } else { throw new CaptchaErrorException(); } } }
public void AddCaptcha(CaptchaState cs) { Captchas.Add(cs.gameMessage.Id, cs); }