A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
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.

78 lines
3.1 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2012 Ben Kurtovic <ben.kurtovic@verizon.net>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. from getpass import getpass
  23. import re
  24. try:
  25. import bcrypt
  26. except ImportError:
  27. bcrypt = None
  28. try:
  29. import yaml
  30. except ImportError:
  31. yaml = None
  32. __all__ = ["ConfigScript"]
  33. class ConfigScript(object):
  34. """A script to guide a user through the creation of a new config file."""
  35. BCRYPT_ROUNDS = 12
  36. def __init__(self, config):
  37. self.config = config
  38. self.data = {}
  39. def _prnt(self, msg):
  40. pass
  41. def _ask_bool(self, text, default=True):
  42. pass
  43. def make_new(self):
  44. """Make a new config file based on the user's input."""
  45. print
  46. self.data["metadata"] = {"version": 1}
  47. self._print("""I can encrypt passwords stored in your config file in
  48. addition to preventing other users on your system from
  49. reading the file. Encryption is recommended is the bot
  50. is to run on a public computer like the Toolserver, but
  51. otherwise the need to enter a key everytime you start
  52. the bot may be annoying.""")
  53. if self._ask_bool("Encrypt stored passwords?"):
  54. self.data["metadata"]["encryptPasswords"] = True
  55. key = getpass("> Enter an encryption key: ")
  56. print "Running {0} rounds of bcrypt...".format(self.BCRYPT_ROUNDS),
  57. signature = bcrypt.hashpw(key, bcrypt.gensalt(self.BCRYPT_ROUNDS))
  58. self.data["metadata"]["signature"] = signature
  59. print " done."
  60. else:
  61. self.data["metadata"]["encryptPasswords"] = False
  62. self._print("""The bot can temporarily store its logs in the logs/
  63. subdirectory. Error logs are kept for a month whereas
  64. normal logs are kept for a week. If you disable this,
  65. the bot will still print logs to stdout.""")
  66. question = "Enable logging?"
  67. self.data["metadata"]["enableLogging"] = self._ask_bool(question)