mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 18:27:59 -05:00
[i18n] Pass over modlog, permissions, reports, streams, trivia, warnings
Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
@@ -4,20 +4,30 @@ import time
|
||||
import random
|
||||
from collections import Counter
|
||||
import discord
|
||||
from redbot.core.bank import deposit_credits
|
||||
from redbot.core.utils.chat_formatting import box
|
||||
from redbot.core import bank
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils.chat_formatting import box, bold, humanize_list
|
||||
from redbot.core.utils.common_filters import normalize_smartquotes
|
||||
from .log import LOG
|
||||
|
||||
__all__ = ["TriviaSession"]
|
||||
|
||||
_REVEAL_MESSAGES = ("I know this one! {}!", "Easy: {}.", "Oh really? It's {} of course.")
|
||||
_FAIL_MESSAGES = (
|
||||
"To the next one I guess...",
|
||||
"Moving on...",
|
||||
"I'm sure you'll know the answer of the next one.",
|
||||
"\N{PENSIVE FACE} Next one.",
|
||||
T_ = Translator("TriviaSession", __file__)
|
||||
|
||||
|
||||
_ = lambda s: s
|
||||
_REVEAL_MESSAGES = (
|
||||
_("I know this one! {answer}!"),
|
||||
_("Easy: {answer}."),
|
||||
_("Oh really? It's {answer} of course."),
|
||||
)
|
||||
_FAIL_MESSAGES = (
|
||||
_("To the next one I guess..."),
|
||||
_("Moving on..."),
|
||||
_("I'm sure you'll know the answer of the next one."),
|
||||
_("\N{PENSIVE FACE} Next one."),
|
||||
)
|
||||
_ = T_
|
||||
|
||||
|
||||
class TriviaSession:
|
||||
@@ -104,7 +114,7 @@ class TriviaSession:
|
||||
async with self.ctx.typing():
|
||||
await asyncio.sleep(3)
|
||||
self.count += 1
|
||||
msg = "**Question number {}!**\n\n{}".format(self.count, question)
|
||||
msg = bold(_("**Question number {num}!").format(num=self.count)) + "\n\n" + question
|
||||
await self.ctx.send(msg)
|
||||
continue_ = await self.wait_for_answer(answers, delay, timeout)
|
||||
if continue_ is False:
|
||||
@@ -113,7 +123,7 @@ class TriviaSession:
|
||||
await self.end_game()
|
||||
break
|
||||
else:
|
||||
await self.ctx.send("There are no more questions!")
|
||||
await self.ctx.send(_("There are no more questions!"))
|
||||
await self.end_game()
|
||||
|
||||
async def _send_startup_msg(self):
|
||||
@@ -121,20 +131,13 @@ class TriviaSession:
|
||||
for idx, tup in enumerate(self.settings["lists"].items()):
|
||||
name, author = tup
|
||||
if author:
|
||||
title = "{} (by {})".format(name, author)
|
||||
title = _("{trivia_list} (by {author})").format(trivia_list=name, author=author)
|
||||
else:
|
||||
title = name
|
||||
list_names.append(title)
|
||||
num_lists = len(list_names)
|
||||
if num_lists > 2:
|
||||
# at least 3 lists, join all but last with comma
|
||||
msg = ", ".join(list_names[: num_lists - 1])
|
||||
# join onto last with "and"
|
||||
msg = " and ".join((msg, list_names[num_lists - 1]))
|
||||
else:
|
||||
# either 1 or 2 lists, join together with "and"
|
||||
msg = " and ".join(list_names)
|
||||
await self.ctx.send("Starting Trivia: " + msg)
|
||||
await self.ctx.send(
|
||||
_("Starting Trivia: {list_names}").format(list_names=humanize_list(list_names))
|
||||
)
|
||||
|
||||
def _iter_questions(self):
|
||||
"""Iterate over questions and answers for this session.
|
||||
@@ -179,20 +182,20 @@ class TriviaSession:
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
if time.time() - self._last_response >= timeout:
|
||||
await self.ctx.send("Guys...? Well, I guess I'll stop then.")
|
||||
await self.ctx.send(_("Guys...? Well, I guess I'll stop then."))
|
||||
self.stop()
|
||||
return False
|
||||
if self.settings["reveal_answer"]:
|
||||
reply = random.choice(_REVEAL_MESSAGES).format(answers[0])
|
||||
reply = T_(random.choice(_REVEAL_MESSAGES)).format(answer=answers[0])
|
||||
else:
|
||||
reply = random.choice(_FAIL_MESSAGES)
|
||||
reply = T_(random.choice(_FAIL_MESSAGES))
|
||||
if self.settings["bot_plays"]:
|
||||
reply += " **+1** for me!"
|
||||
reply += _(" **+1** for me!")
|
||||
self.scores[self.ctx.guild.me] += 1
|
||||
await self.ctx.send(reply)
|
||||
else:
|
||||
self.scores[message.author] += 1
|
||||
reply = "You got it {}! **+1** to you!".format(message.author.display_name)
|
||||
reply = _("You got it {user}! **+1** to you!").format(user=message.author.display_name)
|
||||
await self.ctx.send(reply)
|
||||
return True
|
||||
|
||||
@@ -282,10 +285,16 @@ class TriviaSession:
|
||||
amount = int(multiplier * score)
|
||||
if amount > 0:
|
||||
LOG.debug("Paying trivia winner: %d credits --> %s", amount, str(winner))
|
||||
await deposit_credits(winner, int(multiplier * score))
|
||||
await bank.deposit_credits(winner, int(multiplier * score))
|
||||
await self.ctx.send(
|
||||
"Congratulations, {0}, you have received {1} credits"
|
||||
" for coming first.".format(winner.display_name, amount)
|
||||
_(
|
||||
"Congratulations, {user}, you have received {num} {currency}"
|
||||
" for coming first."
|
||||
).format(
|
||||
user=winner.display_name,
|
||||
num=amount,
|
||||
currency=await bank.get_currency_name(self.ctx.guild),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -313,9 +322,9 @@ def _parse_answers(answers):
|
||||
for answer in answers:
|
||||
if isinstance(answer, bool):
|
||||
if answer is True:
|
||||
ret.extend(["True", "Yes"])
|
||||
ret.extend(["True", "Yes", _("Yes")])
|
||||
else:
|
||||
ret.extend(["False", "No"])
|
||||
ret.extend(["False", "No", _("No")])
|
||||
else:
|
||||
ret.append(str(answer))
|
||||
# Uniquify list
|
||||
|
||||
Reference in New Issue
Block a user