Browse Source

Some fixes and cleanup.

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
3ebee8532e
2 changed files with 19 additions and 12 deletions
  1. +4
    -1
      earwigbot/config/__init__.py
  2. +15
    -11
      earwigbot/config/script.py

+ 4
- 1
earwigbot/config/__init__.py View File

@@ -124,7 +124,10 @@ class BotConfig(object):
if choice.lower().startswith("n"): if choice.lower().startswith("n"):
raise NoConfigError() raise NoConfigError()
else: else:
ConfigScript(self).make_new()
try:
ConfigScript(self).make_new()
except KeyboardInterrupt:
raise NoConfigError()


def _load(self): def _load(self):
"""Load data from our JSON config file (config.yml) into self._data.""" """Load data from our JSON config file (config.yml) into self._data."""


+ 15
- 11
earwigbot/config/script.py View File

@@ -91,14 +91,17 @@ class ConfigScript(object):
def _pause(self): def _pause(self):
raw_input(self.PROMPT + "Press enter to continue: ") raw_input(self.PROMPT + "Press enter to continue: ")


def _ask(self, text, default=None):
def _ask(self, text, default=None, require=True):
text = self.PROMPT + text text = self.PROMPT + text
if default: if default:
text += " \x1b[33m[{0}]\x1b[0m".format(default) text += " \x1b[33m[{0}]\x1b[0m".format(default)
lines = wrap(re.sub("\s\s+", " ", text), self.WIDTH) lines = wrap(re.sub("\s\s+", " ", text), self.WIDTH)
if len(lines) > 1: if len(lines) > 1:
print "\n".join(lines[:-1]) print "\n".join(lines[:-1])
return raw_input(lines[-1] + " ") or default
while True:
answer = raw_input(lines[-1] + " ") or default
if answer or not require:
return answer


def _ask_bool(self, text, default=True): def _ask_bool(self, text, default=True):
text = self.PROMPT + text text = self.PROMPT + text
@@ -149,7 +152,7 @@ class ConfigScript(object):
self.data["metadata"] = OrderedDict([("version", 1)]) self.data["metadata"] = OrderedDict([("version", 1)])
self._print("""I can encrypt passwords stored in your config file in self._print("""I can encrypt passwords stored in your config file in
addition to preventing other users on your system from addition to preventing other users on your system from
reading the file. Encryption is recommended is the bot
reading the file. Encryption is recommended if the bot
is to run on a public computer like the Toolserver, but is to run on a public computer like the Toolserver, but
otherwise the need to enter a key everytime you start otherwise the need to enter a key everytime you start
the bot may be annoying.""") the bot may be annoying.""")
@@ -184,7 +187,7 @@ class ConfigScript(object):
like irc.wikimedia.org, and listens for edits. Users like irc.wikimedia.org, and listens for edits. Users
cannot interact with this component. It can detect cannot interact with this component. It can detect
specific events and report them to "feed" channels on specific events and report them to "feed" channels on
the front-end, or start bot tasks.""")
the front-end or start bot tasks.""")
self._print("""- The wiki task scheduler runs wiki-editing bot tasks in self._print("""- The wiki task scheduler runs wiki-editing bot tasks in
separate threads at user-defined times through a separate threads at user-defined times through a
cron-like interface. Tasks which are not scheduled can cron-like interface. Tasks which are not scheduled can
@@ -249,15 +252,15 @@ class ConfigScript(object):
wikis, like Wikipedia?""") wikis, like Wikipedia?""")
if self._wmf: if self._wmf:
msg = "Site project (e.g. 'wikipedia', 'wiktionary', 'wikimedia'):" msg = "Site project (e.g. 'wikipedia', 'wiktionary', 'wikimedia'):"
self._proj = project = self._ask(msg, default="wikipedia").lower()
self._proj = project = self._ask(msg, "wikipedia").lower()
msg = "Site language code (e.g. 'en', 'fr', 'commons'):" msg = "Site language code (e.g. 'en', 'fr', 'commons'):"
self._lang = lang = self._ask(msg, default="en").lower()
self._lang = lang = self._ask(msg, "en").lower()
kwargs = {"project": project, "lang": lang} kwargs = {"project": project, "lang": lang}
else: else:
msg = "Site base URL, without the script path and trailing slash;" msg = "Site base URL, without the script path and trailing slash;"
msg += " can be protocol-insensitive (e.g. '//en.wikipedia.org'):" msg += " can be protocol-insensitive (e.g. '//en.wikipedia.org'):"
url = self._ask(msg) url = self._ask(msg)
script = self._ask("Site script path:", default="/w")
script = self._ask("Site script path:", "/w")
kwargs = {"base_url": url, "script_path": script} kwargs = {"base_url": url, "script_path": script}


self.data["wiki"]["username"] = self._ask("Bot username:") self.data["wiki"]["username"] = self._ask("Bot username:")
@@ -287,7 +290,7 @@ class ConfigScript(object):
substituted with the bot's username, and $2 with the substituted with the bot's username, and $2 with the
current task number. This can be used to implement a current task number. This can be used to implement a
separate shutoff page for each task.""") separate shutoff page for each task.""")
page = self._ask("Page title:", default="User:$1/Shutoff")
page = self._ask("Page title:", "User:$1/Shutoff")
msg = "Page content to indicate the bot is *not* shut off:" msg = "Page content to indicate the bot is *not* shut off:"
disabled = self._ask(msg, "run") disabled = self._ask(msg, "run")
args = [("page", page), ("disabled", disabled)] args = [("page", page), ("disabled", disabled)]
@@ -306,7 +309,7 @@ class ConfigScript(object):
frontend["ident"] = self._ask("Frontend bot's ident:", frontend["ident"] = self._ask("Frontend bot's ident:",
frontend["nick"].lower()) frontend["nick"].lower())
question = "Frontend bot's real name (gecos):" question = "Frontend bot's real name (gecos):"
frontend["realname"] = self._ask(question)
frontend["realname"] = self._ask(question, "EarwigBot")
if self._ask_bool("Should the bot identify to NickServ?"): if self._ask_bool("Should the bot identify to NickServ?"):
ns_user = self._ask("NickServ username:", frontend["nick"]) ns_user = self._ask("NickServ username:", frontend["nick"])
ns_pass = self._ask_pass("Nickserv password:") ns_pass = self._ask_pass("Nickserv password:")
@@ -323,7 +326,7 @@ class ConfigScript(object):
be easily spoofed. If you have a cloak, this will be easily spoofed. If you have a cloak, this will
probably look like 'wikipedia/Username' or probably look like 'wikipedia/Username' or
'unaffiliated/nickname'.""") 'unaffiliated/nickname'.""")
host = self._ask("Your hostname on the IRC frontend:")
host = self._ask("Your hostname on the frontend:", require=False)
if host: if host:
permdb = self.config._permissions permdb = self.config._permissions
permdb.load() permdb.load()
@@ -347,7 +350,8 @@ class ConfigScript(object):
watcher["nick"] = nick watcher["nick"] = nick
watcher["ident"] = ident watcher["ident"] = ident
question = "Watcher bot's real name (gecos):" question = "Watcher bot's real name (gecos):"
watcher["realname"] = self._ask(question, frontend.get("realname"))
default = frontend.get("realname", "EarwigBot")
watcher["realname"] = self._ask(question, default)
watcher_ns = "Should the bot identify to NickServ?" watcher_ns = "Should the bot identify to NickServ?"
if not self._wmf and self._ask_bool(watcher_ns): if not self._wmf and self._ask_bool(watcher_ns):
ns_user = self._ask("NickServ username:", watcher["nick"]) ns_user = self._ask("NickServ username:", watcher["nick"])


Loading…
Cancel
Save