Compare commits
No commits in common. "31d7cc4284f907b42ed9071ec411dc797063fe4b" and "ae2f7069c738db22909d5b862921e321e811753e" have entirely different histories.
31d7cc4284
...
ae2f7069c7
|
@ -14,7 +14,6 @@ from edmond.plugin import Plugin
|
||||||
|
|
||||||
|
|
||||||
class Bot(irc.client.SimpleIRCClient, Logger):
|
class Bot(irc.client.SimpleIRCClient, Logger):
|
||||||
"""Main class for the IRC bot: handles connection and manages available plugins."""
|
|
||||||
|
|
||||||
CHANNELS_RUNTIME_KEY = "_channels"
|
CHANNELS_RUNTIME_KEY = "_channels"
|
||||||
|
|
||||||
|
@ -195,7 +194,7 @@ class Bot(irc.client.SimpleIRCClient, Logger):
|
||||||
if self.done:
|
if self.done:
|
||||||
return
|
return
|
||||||
self.log_i("Stopping Edmond.")
|
self.log_i("Stopping Edmond.")
|
||||||
self.save_storage()
|
self.__save_storage()
|
||||||
if self.connection.is_connected():
|
if self.connection.is_connected():
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
self.done = True
|
self.done = True
|
||||||
|
|
|
@ -9,15 +9,6 @@ from edmond.plugin import Plugin
|
||||||
|
|
||||||
|
|
||||||
class TranslatePlugin(Plugin):
|
class TranslatePlugin(Plugin):
|
||||||
"""Translate text using the `translate` package.
|
|
||||||
|
|
||||||
The translate package can use a bunch of translation interfaces but the default is
|
|
||||||
MyMemory which is fine for our purposes. There are two ways to ask for a
|
|
||||||
translation:
|
|
||||||
- Without any additional params, the source language is autodetected and the target
|
|
||||||
language is specified in the config file;
|
|
||||||
- With BOTH source and target languages.
|
|
||||||
"""
|
|
||||||
|
|
||||||
REQUIRED_CONFIGS = [
|
REQUIRED_CONFIGS = [
|
||||||
"commands",
|
"commands",
|
||||||
|
@ -51,12 +42,19 @@ class TranslatePlugin(Plugin):
|
||||||
|
|
||||||
def parse_words(self, words):
|
def parse_words(self, words):
|
||||||
"""Parse given words for parameters and return (from, to, text)."""
|
"""Parse given words for parameters and return (from, to, text)."""
|
||||||
# If no language specification is found, use default params.
|
from_lang = "autodetect"
|
||||||
if (
|
to_lang = self.config["default_dest"]
|
||||||
len(words) < 5
|
num_param_found = 0
|
||||||
or words[0] != self.config["param_source"]
|
for word in words:
|
||||||
or words[2] != self.config["param_dest"]
|
if not word.startswith("!"):
|
||||||
):
|
break
|
||||||
return "autodetect", self.config["default_dest"], " ".join(words)
|
num_param_found += 1
|
||||||
# Else use the parameters provided.
|
param_word = word.lstrip("!")
|
||||||
return words[1], words[3], " ".join(words[4:])
|
if not ":" in param_word:
|
||||||
|
continue
|
||||||
|
param_name, param_value = param_word.split(":")
|
||||||
|
if param_name == self.config["param_source"]:
|
||||||
|
from_lang = param_value
|
||||||
|
elif param_name == self.config["param_dest"]:
|
||||||
|
to_lang = param_value
|
||||||
|
return from_lang, to_lang, " ".join(words[num_param_found:])
|
||||||
|
|
Loading…
Reference in a new issue