mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[V3 Trivia] Allow crediting the author of trivia lists (#1197)
* Credit author of trivia lists * Use proper sentences * Remove unwanted traceback print
This commit is contained in:
parent
68800d28fc
commit
fb0190f826
@ -96,10 +96,13 @@ class TriviaSession():
|
|||||||
In order for the trivia session to be stopped correctly, this should
|
In order for the trivia session to be stopped correctly, this should
|
||||||
only be called internally by `TriviaSession.start`.
|
only be called internally by `TriviaSession.start`.
|
||||||
"""
|
"""
|
||||||
|
await self._send_startup_msg()
|
||||||
max_score = self.settings["max_score"]
|
max_score = self.settings["max_score"]
|
||||||
delay = self.settings["delay"]
|
delay = self.settings["delay"]
|
||||||
timeout = self.settings["timeout"]
|
timeout = self.settings["timeout"]
|
||||||
for question, answers in self._iter_questions():
|
for question, answers in self._iter_questions():
|
||||||
|
async with self.ctx.typing():
|
||||||
|
await asyncio.sleep(3)
|
||||||
self.count += 1
|
self.count += 1
|
||||||
msg = "**Question number {}!**\n\n{}".format(self.count, question)
|
msg = "**Question number {}!**\n\n{}".format(self.count, question)
|
||||||
await self.ctx.send(msg)
|
await self.ctx.send(msg)
|
||||||
@ -109,12 +112,30 @@ class TriviaSession():
|
|||||||
if any(score >= max_score for score in self.scores.values()):
|
if any(score >= max_score for score in self.scores.values()):
|
||||||
await self.end_game()
|
await self.end_game()
|
||||||
break
|
break
|
||||||
async with self.ctx.typing():
|
|
||||||
await asyncio.sleep(3)
|
|
||||||
else:
|
else:
|
||||||
await self.ctx.send("There are no more questions!")
|
await self.ctx.send("There are no more questions!")
|
||||||
await self.end_game()
|
await self.end_game()
|
||||||
|
|
||||||
|
async def _send_startup_msg(self):
|
||||||
|
list_names = []
|
||||||
|
for idx, tup in enumerate(self.settings["lists"].items()):
|
||||||
|
name, author = tup
|
||||||
|
if author:
|
||||||
|
title = "{} (by {})".format(name, 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)
|
||||||
|
|
||||||
def _iter_questions(self):
|
def _iter_questions(self):
|
||||||
"""Iterate over questions and answers for this session.
|
"""Iterate over questions and answers for this session.
|
||||||
|
|
||||||
|
|||||||
@ -178,6 +178,7 @@ class Trivia:
|
|||||||
"There is already an ongoing trivia session in this channel.")
|
"There is already an ongoing trivia session in this channel.")
|
||||||
return
|
return
|
||||||
trivia_dict = {}
|
trivia_dict = {}
|
||||||
|
authors = []
|
||||||
for category in reversed(categories):
|
for category in reversed(categories):
|
||||||
# We reverse the categories so that the first list's config takes
|
# We reverse the categories so that the first list's config takes
|
||||||
# priority over the others.
|
# priority over the others.
|
||||||
@ -193,6 +194,7 @@ class Trivia:
|
|||||||
" incorrectly.".format(category))
|
" incorrectly.".format(category))
|
||||||
else:
|
else:
|
||||||
trivia_dict.update(dict_)
|
trivia_dict.update(dict_)
|
||||||
|
authors.append(trivia_dict.pop("AUTHOR", None))
|
||||||
continue
|
continue
|
||||||
return
|
return
|
||||||
if not trivia_dict:
|
if not trivia_dict:
|
||||||
@ -203,6 +205,7 @@ class Trivia:
|
|||||||
config = trivia_dict.pop("CONFIG", None)
|
config = trivia_dict.pop("CONFIG", None)
|
||||||
if config and settings["allow_override"]:
|
if config and settings["allow_override"]:
|
||||||
settings.update(config)
|
settings.update(config)
|
||||||
|
settings["lists"] = dict(zip(categories, reversed(authors)))
|
||||||
session = TriviaSession.start(ctx, trivia_dict, settings)
|
session = TriviaSession.start(ctx, trivia_dict, settings)
|
||||||
self.trivia_sessions.append(session)
|
self.trivia_sessions.append(session)
|
||||||
LOG.debug("New trivia session; #%s in %d", ctx.channel, ctx.guild.id)
|
LOG.debug("New trivia session; #%s in %d", ctx.channel, ctx.guild.id)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user