Преглед изворни кода

Clean up command more (#30)

tags/v0.1^2
Ben Kurtovic пре 12 година
родитељ
комит
d338dc15c5
1 измењених фајлова са 31 додато и 29 уклоњено
  1. +31
    -29
      earwigbot/commands/lag.py

+ 31
- 29
earwigbot/commands/lag.py Прегледај датотеку

@@ -29,39 +29,41 @@ class Lag(Command):
commands = ["lag", "replag", "maxlag"]

def process(self, data):
if data.kwargs and "project" in data.kwargs and "lang" in data.kwargs:
project, lang = data.kwargs["project"], data.kwargs["lang"]
site = self.get_site(data, project, lang)
if not site:
return
elif data.args:
if len(data.args) > 1:
name = " ".join(data.args)
self.reply(data, "unknown site: \x0302{0}\x0F.".format(name))
return
name = data.args[0]
if "." in name:
lang, project = name.split(".")[:2]
elif ":" in name:
project, lang = name.split(":")[:2]
else:
try:
site = self.bot.wiki.get_site(name)
except exceptions.SiteNotFoundError:
msg = "unknown site: \x0302{0}\x0F.".format(name)
self.reply(data, msg)
return
site = self.get_site(data, project, lang)
if not site:
return
else:
site = self.bot.wiki.get_site()
site = self.get_site(data)
if not site:
return

msg = "\x0302{0}\x0F: Toolserver replag is {1} seconds; database maxlag is {2} seconds"
msg = "\x0302{0}\x0F: Toolserver replag is {1} seconds; database maxlag is {2} seconds."
msg = msg.format(site.name, site.get_replag(), site.get_maxlag())
self.reply(data, msg)

def get_site(self, data, project, lang):
def get_site(self):
if data.kwargs and "project" in data.kwargs and "lang" in data.kwargs:
project, lang = data.kwargs["project"], data.kwargs["lang"]
return self.get_site_from_proj_and_lang(data, project, lang)

if not data.args:
return self.bot.wiki.get_site()

if len(data.args) > 1:
name = " ".join(data.args)
self.reply(data, "unknown site: \x0302{0}\x0F.".format(name))
return
name = data.args[0]
if "." in name:
lang, project = name.split(".")[:2]
elif ":" in name:
project, lang = name.split(":")[:2]
else:
try:
return self.bot.wiki.get_site(name)
except exceptions.SiteNotFoundError:
msg = "unknown site: \x0302{0}\x0F.".format(name)
self.reply(data, msg)
return
return self.get_site_from_proj_and_lang(data, project, lang)

def get_site_from_proj_and_lang(self, data, project, lang):
try:
site = self.bot.wiki.get_site(project=project, lang=lang)
except exceptions.SiteNotFoundError:


Loading…
Откажи
Сачувај