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.

153 lines
4.7KB

  1. import sys
  2. import time
  3. class Colours:
  4. HEADER = '\033[95m'
  5. OKBLUE = '\033[94m'
  6. OKGREEN = '\033[92m'
  7. WARNING = '\033[93m'
  8. FAIL = '\033[91m'
  9. ENDC = '\033[0m'
  10. BOLD = '\033[1m'
  11. UNDERLINE = '\033[4m'
  12. INFO = "[{} INFO {}]".format(Colours.OKBLUE, Colours.ENDC)
  13. OK = "[{} OK {}]".format(Colours.OKGREEN, Colours.ENDC)
  14. WARN = "[{} WARN {}]".format(Colours.WARNING, Colours.ENDC)
  15. ERROR = "[{} ERROR {}]".format(Colours.FAIL, Colours.ENDC)
  16. INPUT = "[{} .... {}]".format(Colours.OKBLUE, Colours.ENDC)
  17. # Version Checking
  18. # Basically reject anything not 3.5 or 3.6 as those are the only versions that work.
  19. if not (sys.version_info[:2] == (3, 5) or sys.version_info[:2] == (3, 6) or sys.version_info[:2] == (3, 7)):
  20. print("{0} Roxbot does not support Python {1}.{2}. Roxbot only works on 3.5 - 2.7".format(ERROR, sys.version_info[0], sys.version_info[1]))
  21. exit(0)
  22. else:
  23. import configparser
  24. # Install Requirements
  25. def requirements():
  26. print("{} Installing requirements".format(INFO))
  27. args = ["install", "-U", "-r", "requirements.txt", "--user"]
  28. if '-v' not in sys.argv:
  29. args.append("-q")
  30. try:
  31. import pip
  32. code = pip.main(args)
  33. except AttributeError: # Has pip 10 installed
  34. from pip._internal import main
  35. code = main(args)
  36. except ImportError:
  37. print("{} Pip not installed. Please install pip before continuing.".format(ERROR))
  38. exit(1)
  39. if code != 0:
  40. print("{} Error occurred while installing requirements. Please use the option '-v' to get verbose output from pip".format(ERROR))
  41. print("{} Exiting...".format(ERROR))
  42. exit(1)
  43. else:
  44. print("{} Requirements successfully installed.".format(OK))
  45. # Create preferences file.
  46. def create_preferences_file():
  47. time.sleep(.5)
  48. print("{} Creating preferences.ini file...".format(INFO))
  49. with open("roxbot/settings/preferences_example.ini", "r") as orig:
  50. fp = orig.read()
  51. with open("roxbot/settings/preferences.ini", "w") as new:
  52. new.write(fp)
  53. time.sleep(.5)
  54. print("{} Preferences file created".format(OK))
  55. time.sleep(.5)
  56. def preferences_setup():
  57. # Ask to do preferences.ini setup
  58. print("{} Most of the setup is complete. All there is to do is setup the preferences.ini file.".format(INFO))
  59. print("{} You can do the quick setup in this script, or manually setup the file yourself.".format(INFO))
  60. print("")
  61. while True:
  62. choice = input("{} Do you want to continue to the easy preferences setup? (y/n): ".format(INFO))
  63. if choice.strip(" ").lower() == "y":
  64. time.sleep(.5)
  65. print("")
  66. print("{} Everything asked for next is required. Please try and input every option. "
  67. "If not possible, it is required you fix this in the preferences.ini file later.".format(WARN))
  68. print("")
  69. break
  70. elif choice.strip(" ").lower() == "n":
  71. print("{} Exiting...".format(OK))
  72. exit(0)
  73. # Preferences.ini setup
  74. config = configparser.ConfigParser()
  75. config.read("roxbot/settings/preferences.ini")
  76. print("{} Setting up preferences file...".format(INFO))
  77. # OWNER ID
  78. owner_id = str(input("{} Bot Owner ID: ".format(INPUT))).strip(" ")
  79. if not owner_id or not owner_id.isdigit():
  80. print("{} Invalid owner ID given. Skipping...".format(WARN))
  81. else:
  82. config["Roxbot"]["OwnerID"] = owner_id
  83. print("{} OWNER ID set to '{}'".format(OK, owner_id))
  84. print("")
  85. # COMMAND PREFIX
  86. prefix = str(input("{} Command Prefix: ".format(INPUT))).strip(" ")
  87. if not prefix:
  88. print("{} Invalid Command Prefix given. Skipping...".format(WARN))
  89. else:
  90. config["Roxbot"]["Command_Prefix"] = prefix
  91. print("{} COMMAND PREFIX set to '{}'".format(OK, prefix))
  92. print("")
  93. # BOT TOKEN
  94. token = str(input("{} Discord Bot Token: ".format(INPUT))).strip(" ")
  95. if not token:
  96. print("{} Invalid token given. Skipping...".format(WARN))
  97. else:
  98. config["Tokens"]["Discord"] = token
  99. print("{} DISCORD TOKEN set to '{}'".format(OK, token))
  100. print("")
  101. # IMGUR CLIENT ID
  102. token = str(input("{} Imgur Client ID: ".format(INPUT))).strip(" ")
  103. if not token:
  104. print("{} Invalid client ID given. Skipping...".format(WARN))
  105. else:
  106. config["Tokens"]["Imgur"] = token
  107. print("{} IMGUR ID set to '{}'".format(OK, token))
  108. print("")
  109. # SAVE
  110. # TODO: Add comments back in once preferences.ini has been rewritten
  111. print("{} Finished preferences.ini setup.".format(OK))
  112. with open("roxbot/settings/preferences.ini", 'w') as configfile:
  113. config.write(configfile)
  114. print("{} There are more options avaliable in the file (found at ./roxbot/settings/preferences.ini) if you want to make optional tweaks to Roxbot.".format(INFO))
  115. print("{} Exiting...".format(OK))
  116. exit(0)
  117. def main():
  118. try:
  119. requirements()
  120. create_preferences_file()
  121. preferences_setup()
  122. except KeyboardInterrupt:
  123. print("")
  124. print("{} Install script ended via KeyboardInterrupt".format(ERROR))
  125. if __name__ == "__main__":
  126. main()