vrobot3 is a chat bot for IRC and Discord.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.2KB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // Copyright © 2016 Project Golan
  4. //
  5. // See "LICENSE" for more information.
  6. //
  7. //-----------------------------------------------------------------------------
  8. //
  9. // Program entry point.
  10. //
  11. //-----------------------------------------------------------------------------
  12. using System;
  13. using System.Threading;
  14. using System.Collections.Generic;
  15. using System.IO;
  16. using Newtonsoft.Json;
  17. namespace ProjectGolan.Vrobot3
  18. {
  19. //
  20. // Program
  21. //
  22. public class Program
  23. {
  24. //
  25. // ProgramInfo
  26. //
  27. public struct ProgramInfo
  28. {
  29. public String googleKey;
  30. }
  31. //
  32. // JsonConfig
  33. //
  34. private struct JsonConfig
  35. {
  36. public ProgramInfo info;
  37. public BotInfo[] servers;
  38. }
  39. private readonly List<Bot> bots = new List<Bot>();
  40. private readonly List<Thread> threads = new List<Thread>();
  41. public String dataDir = "../data";
  42. public ProgramInfo info;
  43. public static Program Instance;
  44. //
  45. // Main
  46. //
  47. [STAThread]
  48. public static void Main(String[] args)
  49. {
  50. Instance = new Program();
  51. Instance.main(args);
  52. }
  53. //
  54. // main
  55. //
  56. public void main(String[] args)
  57. {
  58. try
  59. {
  60. var configFile = File.ReadAllText(dataDir + "/config.json");
  61. var config = JsonConvert.DeserializeObject<JsonConfig>(configFile);
  62. info = config.info;
  63. foreach(var server in config.servers)
  64. threads.AddItem(new Thread(bots.AddItem(new Bot(server)).connect)).Start();
  65. }
  66. catch(Exception exc)
  67. {
  68. File.WriteAllText(dataDir + "/excdump.txt", exc.ToString());
  69. Console.WriteLine("Error: {0}", exc.Message);
  70. }
  71. }
  72. //
  73. // end
  74. //
  75. public void end()
  76. {
  77. foreach(var bot in bots)
  78. try { bot.disconnect(); }
  79. catch(Exception exc)
  80. {
  81. File.WriteAllText(dataDir + "/disconnectexcdump.txt",
  82. exc.ToString());
  83. }
  84. bots.Clear();
  85. threads.Clear();
  86. }
  87. }
  88. }
  89. // EOF