aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2022-11-29 20:25:56 +0000
committerGravatar GitHub <[email protected]>2022-11-29 20:25:56 +0000
commit28530891d2fb92833a2e035cbf0d3fa8282e120f (patch)
tree8fa4ecd3a501a9ac1e827d422641d9d9ac177b7a
parentFetch active nominations from the API for !server command (diff)
parentMerge pull request #2349 from python-discord/record-help-channel-claims (diff)
Merge branch 'main' into dont-use-removed-talentpool-cache
-rw-r--r--bot/exts/help_channels/_channel.py1
-rw-r--r--bot/exts/help_channels/_stats.py10
-rw-r--r--bot/resources/tags/return.md19
-rw-r--r--bot/utils/channel.py4
4 files changed, 17 insertions, 17 deletions
diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py
index 0cee24817..5c47a3559 100644
--- a/bot/exts/help_channels/_channel.py
+++ b/bot/exts/help_channels/_channel.py
@@ -117,6 +117,7 @@ async def send_opened_post_dm(post: discord.Thread) -> None:
async def help_post_opened(opened_post: discord.Thread, *, reopen: bool = False) -> None:
"""Apply new post logic to a new help forum post."""
_stats.report_post_count()
+ bot.instance.stats.incr("help.claimed")
if not isinstance(opened_post.owner, discord.Member):
log.debug(f"{opened_post.owner_id} isn't a member. Closing post.")
diff --git a/bot/exts/help_channels/_stats.py b/bot/exts/help_channels/_stats.py
index 8ab93f19d..1075b439e 100644
--- a/bot/exts/help_channels/_stats.py
+++ b/bot/exts/help_channels/_stats.py
@@ -23,7 +23,7 @@ class ClosingReason(Enum):
def report_post_count() -> None:
"""Report post count stats of the help forum."""
help_forum = bot.instance.get_channel(constants.Channels.help_system_forum)
- bot.instance.stats.gauge("help_forum.total.in_use", len(help_forum.threads))
+ bot.instance.stats.gauge("help.total.in_use", len(help_forum.threads))
async def report_complete_session(help_session_post: discord.Thread, closed_on: ClosingReason) -> None:
@@ -32,13 +32,13 @@ async def report_complete_session(help_session_post: discord.Thread, closed_on:
`closed_on` is the reason why the post was closed. See `ClosingReason` for possible reasons.
"""
- bot.instance.stats.incr(f"help_forum.dormant_calls.{closed_on.value}")
+ bot.instance.stats.incr(f"help.dormant_calls.{closed_on.value}")
open_time = discord.utils.snowflake_time(help_session_post.id)
in_use_time = arrow.utcnow() - open_time
- bot.instance.stats.timing("help_forum.in_use_time", in_use_time)
+ bot.instance.stats.timing("help.in_use_time", in_use_time)
if await _caches.posts_with_non_claimant_messages.get(help_session_post.id):
- bot.instance.stats.incr("help_forum.sessions.answered")
+ bot.instance.stats.incr("help.sessions.answered")
else:
- bot.instance.stats.incr("help_forum.sessions.unanswered")
+ bot.instance.stats.incr("help.sessions.unanswered")
diff --git a/bot/resources/tags/return.md b/bot/resources/tags/return.md
index e37f0eebc..1d65ab1ae 100644
--- a/bot/resources/tags/return.md
+++ b/bot/resources/tags/return.md
@@ -1,27 +1,25 @@
**Return Statement**
-When calling a function, you'll often want it to give you a value back. In order to do that, you must `return` it. The reason for this is because functions have their own scope. Any values defined within the function body are inaccessible outside of that function.
-
-*For more information about scope, see `!tags scope`*
+A value created inside a function can't be used outside of it unless you `return` it.
Consider the following function:
```py
def square(n):
- return n*n
+ return n * n
```
-If we wanted to store 5 squared in a variable called `x`, we could do that like so:
+If we wanted to store 5 squared in a variable called `x`, we would do:
`x = square(5)`. `x` would now equal `25`.
**Common Mistakes**
```py
>>> def square(n):
-... n*n # calculates then throws away, returns None
+... n * n # calculates then throws away, returns None
...
>>> x = square(5)
>>> print(x)
None
>>> def square(n):
-... print(n*n) # calculates and prints, then throws away and returns None
+... print(n * n) # calculates and prints, then throws away and returns None
...
>>> x = square(5)
25
@@ -29,7 +27,6 @@ None
None
```
**Things to note**
-• `print()` and `return` do **not** accomplish the same thing. `print()` will only print the value, it will not be accessible outside of the function afterwards.
-• A function will return `None` if it ends without reaching an explicit `return` statement.
-• When you want to print a value calculated in a function, instead of printing inside the function, it is often better to return the value and print the *function call* instead.
-• [Official documentation for `return`](https://docs.python.org/3/reference/simple_stmts.html#the-return-statement)
+• `print()` and `return` do **not** accomplish the same thing. `print()` will show the value, and then it will be gone.
+• A function will return `None` if it ends without a `return` statement.
+• When you want to print a value from a function, it's best to return the value and print the *function call* instead, like `print(square(5))`.
diff --git a/bot/utils/channel.py b/bot/utils/channel.py
index 821a3732a..20f433a3f 100644
--- a/bot/utils/channel.py
+++ b/bot/utils/channel.py
@@ -48,7 +48,9 @@ def is_in_category(channel: discord.TextChannel, category_id: int) -> bool:
return getattr(channel, "category_id", None) == category_id
-async def get_or_fetch_channel(channel_id: int) -> discord.abc.GuildChannel:
+async def get_or_fetch_channel(
+ channel_id: int
+) -> discord.abc.GuildChannel | discord.abc.PrivateChannel | discord.Thread:
"""Attempt to get or fetch a channel and return it."""
log.trace(f"Getting the channel {channel_id}.")