Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nono
Babelbot
Commits
d3f5fd11
Commit
d3f5fd11
authored
May 29, 2021
by
Sébastien Dufromentel
Browse files
Message parsing improved (but still room for improvements)
parent
8c064615
Changes
1
Hide whitespace changes
Inline
Side-by-side
BabelBot.py
View file @
d3f5fd11
...
...
@@ -50,18 +50,21 @@ def usernick(botnick, lang):
return
None
# Not a bot nick.
nick
=
botnick
[:
-
len
(
lang
)
-
1
]
# Cleaning…
return
irc
.
strings
.
IRCFoldedCase
(
nick
[:
-
1
]
+
"]"
if
user
nick
.
endswith
(
"|"
)
else
nick
)
if
nick
.
endswith
(
"|"
)
else
nick
[:
-
1
]
)
def
translate
(
message
,
target
):
try
:
# Don't interrupt.
if
message
==
"\o/"
:
return
message
#TODO replace nick/nick[lang] correctly.
for
nick
in
bots
.
keys
():
if
nick
in
message
:
message
=
message
.
replace
(
nick
,
usernick
(
nick
,
target
))
with
urllib
.
request
.
urlopen
(
trans
,
urllib
.
parse
.
urlencode
({
"source"
:
"auto"
,
"target"
:
target
,
"q"
:
message
}).
encode
())
as
f
:
return
json
.
loads
(
f
.
read
())[
"translatedText"
]
except
Exception
:
# Probably a server error.
return
"�[ "
+
message
+
" ]�"
__import__
(
"traceback"
).
print_exc
()
return
message
class
data
(
object
):
def
__init__
(
self
,
**
args
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment