Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. [Command("sync")]
  2. public async Task sync(CommandContext ctx) {
  3. /*
  4. * MongoDb
  5. */
  6. Dictionary<string, ulong> nametoid = new Dictionary<string, ulong> ();
  7. nametoid.Add("Paulo",155774074885242880);
  8. nametoid.Add("TheSheepFM 🌵",230127500179668992);
  9. nametoid.Add("Wysel",272792153623887872);
  10. nametoid.Add("Fereis",248151841651687424);
  11. nametoid.Add("CNaville",205133485428572160);
  12. nametoid.Add("[UBGE] Luiz", 322745409074102282);
  13. nametoid.Add("[UBGE] Roberto M.", 218160728496930816);
  14. nametoid.Add("injured", 252489453807861770);
  15. nametoid.Add("Injured", 252489453807861770);
  16. nametoid.Add("TheSheepFM", 230127500179668992);
  17. nametoid.Add("[UBGE] Léo Freitas", 95614784350715904);
  18. nametoid.Add("[UBGE] Ale184", 173480386343469056);
  19. nametoid.Add("CØNGO", 95614784350715904);
  20. var client = new MongoClient();
  21. var local = client.GetDatabase(UBGEbot.MongoConfig.DbName);
  22. var Infra = local.GetCollection<Infracao>("Infra");
  23. /*
  24. * Google Sheets
  25. */
  26. var read = new GoogleSheets.Read();
  27. var responce = await read.This(UBGEbot.ApiConfig.InfracaoID, UBGEbot.ApiConfig.InfracaoRange);
  28. List<Infracao> infracoes = new List<Infracao>();
  29. foreach (var row in responce) {
  30. if (!String.IsNullOrWhiteSpace(row[0].ToString())) {
  31. Infracao infra = new Infracao();
  32. infra.dataInfracao = DateTime.Parse(row[0].ToString());
  33. infra.idInfrator = ulong.Parse(row[1].ToString());
  34. if (nametoid.ContainsKey(row[4].ToString()))
  35. {
  36. infra.idStaff = nametoid[row[4].ToString()];
  37. }
  38. else {
  39. infra.idStaff = nametoid["Paulo"];
  40. }
  41.  
  42. infra.preso = false;
  43. infra.motivoInfracao = row[3].ToString();
  44. var x = new LogPrisao();
  45. x.tempo = "Sem dados";
  46. x.cargos = null;
  47. infra.dadosPrisao = x;
  48. await Infra.InsertOneAsync(infra);
  49. Console.WriteLine($"Infração adicionada : {responce.IndexOf(row)} / {responce.Count}");
  50. }
  51. }
  52. await ctx.RespondAsync("DB Sincronizada com o GoogleSheets");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement