aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/bot.py2
-rw-r--r--bot/cogs/filtering.py10
-rw-r--r--bot/cogs/python_news.py6
-rw-r--r--bot/cogs/reddit.py8
-rw-r--r--bot/cogs/snekbox.py21
-rw-r--r--bot/cogs/stats.py17
-rw-r--r--config-default.yml2
-rw-r--r--tests/bot/cogs/test_snekbox.py6
8 files changed, 64 insertions, 8 deletions
diff --git a/bot/cogs/bot.py b/bot/cogs/bot.py
index f6aea51c5..a79b37d25 100644
--- a/bot/cogs/bot.py
+++ b/bot/cogs/bot.py
@@ -326,6 +326,8 @@ class BotCog(Cog, name="Bot"):
log.trace("The code consists only of expressions, not sending instructions")
if howto != "":
+ # Increase amount of codeblock correction in stats
+ self.bot.stats.incr("codeblock_corrections")
howto_embed = Embed(description=howto)
bot_message = await msg.channel.send(f"Hey {msg.author.mention}!", embed=howto_embed)
self.codeblock_message_ids[msg.id] = bot_message.id
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py
index 6a703f5a1..1e21a4ce3 100644
--- a/bot/cogs/filtering.py
+++ b/bot/cogs/filtering.py
@@ -4,7 +4,7 @@ from typing import Optional, Union
import discord.errors
from dateutil.relativedelta import relativedelta
-from discord import Colour, DMChannel, Member, Message, TextChannel
+from discord import Colour, Member, Message, TextChannel
from discord.ext.commands import Cog
from discord.utils import escape_markdown
@@ -161,8 +161,10 @@ class Filtering(Cog):
match = await _filter["function"](msg)
if match:
- # If this is a filter (not a watchlist), we should delete the message.
- if _filter["type"] == "filter":
+ is_private = msg.channel.type is discord.ChannelType.private
+
+ # If this is a filter (not a watchlist) and not in a DM, delete the message.
+ if _filter["type"] == "filter" and not is_private:
try:
# Embeds (can?) trigger both the `on_message` and `on_message_edit`
# event handlers, triggering filtering twice for the same message.
@@ -181,7 +183,7 @@ class Filtering(Cog):
if _filter["user_notification"]:
await self.notify_member(msg.author, _filter["notification_msg"], msg.channel)
- if isinstance(msg.channel, DMChannel):
+ if is_private:
channel_str = "via DM"
else:
channel_str = f"in {msg.channel.mention}"
diff --git a/bot/cogs/python_news.py b/bot/cogs/python_news.py
index 57ce61638..d28af4a0b 100644
--- a/bot/cogs/python_news.py
+++ b/bot/cogs/python_news.py
@@ -109,6 +109,9 @@ class PythonNews(Cog):
)
payload["data"]["pep"].append(pep_nr)
+ # Increase overall PEP new stat
+ self.bot.stats.incr("python_news.posted.pep")
+
if msg.channel.is_news():
log.trace("Publishing PEP annnouncement because it was in a news channel")
await msg.publish()
@@ -168,6 +171,9 @@ class PythonNews(Cog):
)
payload["data"][maillist].append(thread_information["thread_id"])
+ # Increase this specific maillist counter in stats
+ self.bot.stats.incr(f"python_news.posted.{maillist.replace('-', '_')}")
+
if msg.channel.is_news():
log.trace("Publishing mailing list message because it was in a news channel")
await msg.publish()
diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py
index 5f2aec7a5..3b77538a0 100644
--- a/bot/cogs/reddit.py
+++ b/bot/cogs/reddit.py
@@ -218,7 +218,10 @@ class Reddit(Cog):
for subreddit in RedditConfig.subreddits:
top_posts = await self.get_top_posts(subreddit=subreddit, time="day")
- await self.webhook.send(username=f"{subreddit} Top Daily Posts", embed=top_posts)
+ message = await self.webhook.send(username=f"{subreddit} Top Daily Posts", embed=top_posts, wait=True)
+
+ if message.channel.is_news():
+ await message.publish()
async def top_weekly_posts(self) -> None:
"""Post a summary of the top posts."""
@@ -242,6 +245,9 @@ class Reddit(Cog):
await message.pin()
+ if message.channel.is_news():
+ await message.publish()
+
@group(name="reddit", invoke_without_command=True)
async def reddit_group(self, ctx: Context) -> None:
"""View the top posts from various subreddits."""
diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py
index c2782b9c8..a2a7574d4 100644
--- a/bot/cogs/snekbox.py
+++ b/bot/cogs/snekbox.py
@@ -47,6 +47,7 @@ EVAL_ROLES = (Roles.helpers, Roles.moderators, Roles.admins, Roles.owners, Roles
SIGKILL = 9
REEVAL_EMOJI = '\U0001f501' # :repeat:
+REEVAL_TIMEOUT = 30
class Snekbox(Cog):
@@ -205,6 +206,12 @@ class Snekbox(Cog):
if paste_link:
msg = f"{msg}\nFull output: {paste_link}"
+ # Collect stats of eval fails + successes
+ if icon == ":x:":
+ self.bot.stats.incr("snekbox.python.fail")
+ else:
+ self.bot.stats.incr("snekbox.python.success")
+
response = await ctx.send(msg)
self.bot.loop.create_task(
wait_for_deletion(response, user_ids=(ctx.author.id,), client=ctx.bot)
@@ -227,7 +234,7 @@ class Snekbox(Cog):
_, new_message = await self.bot.wait_for(
'message_edit',
check=_predicate_eval_message_edit,
- timeout=10
+ timeout=REEVAL_TIMEOUT
)
await ctx.message.add_reaction(REEVAL_EMOJI)
await self.bot.wait_for(
@@ -292,6 +299,18 @@ class Snekbox(Cog):
await ctx.send_help(ctx.command)
return
+ if Roles.helpers in (role.id for role in ctx.author.roles):
+ self.bot.stats.incr("snekbox_usages.roles.helpers")
+ else:
+ self.bot.stats.incr("snekbox_usages.roles.developers")
+
+ if ctx.channel.category_id == Categories.help_in_use:
+ self.bot.stats.incr("snekbox_usages.channels.help")
+ elif ctx.channel.id == Channels.bot_commands:
+ self.bot.stats.incr("snekbox_usages.channels.bot_commands")
+ else:
+ self.bot.stats.incr("snekbox_usages.channels.topical")
+
log.info(f"Received code from {ctx.author} for evaluation:\n{code}")
while True:
diff --git a/bot/cogs/stats.py b/bot/cogs/stats.py
index d253db913..9baf222e2 100644
--- a/bot/cogs/stats.py
+++ b/bot/cogs/stats.py
@@ -2,8 +2,10 @@ import string
from datetime import datetime
from discord import Member, Message, Status
-from discord.ext.commands import Bot, Cog, Context
+from discord.ext.commands import Cog, Context
+from discord.ext.tasks import loop
+from bot.bot import Bot
from bot.constants import Channels, Guild, Stats as StatConf
@@ -23,6 +25,7 @@ class Stats(Cog):
def __init__(self, bot: Bot):
self.bot = bot
self.last_presence_update = None
+ self.update_guild_boost.start()
@Cog.listener()
async def on_message(self, message: Message) -> None:
@@ -101,6 +104,18 @@ class Stats(Cog):
self.bot.stats.gauge("guild.status.do_not_disturb", dnd)
self.bot.stats.gauge("guild.status.offline", offline)
+ @loop(hours=1)
+ async def update_guild_boost(self) -> None:
+ """Post the server boost level and tier every hour."""
+ await self.bot.wait_until_guild_available()
+ g = self.bot.get_guild(Guild.id)
+ self.bot.stats.gauge("boost.amount", g.premium_subscription_count)
+ self.bot.stats.gauge("boost.tier", g.premium_tier)
+
+ def cog_unload(self) -> None:
+ """Stop the boost statistic task on unload of the Cog."""
+ self.update_guild_boost.stop()
+
def setup(bot: Bot) -> None:
"""Load the stats cog."""
diff --git a/config-default.yml b/config-default.yml
index 2e8a777ba..2e98186f1 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -316,6 +316,8 @@ filter:
- poweredbydialup.online
- poweredbysecurity.org
- poweredbysecurity.online
+ - ssteam.site
+ - steamwalletgift.com
word_watchlist:
- goo+ks*
diff --git a/tests/bot/cogs/test_snekbox.py b/tests/bot/cogs/test_snekbox.py
index 8490b02ca..14299e766 100644
--- a/tests/bot/cogs/test_snekbox.py
+++ b/tests/bot/cogs/test_snekbox.py
@@ -290,7 +290,11 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(actual, expected)
self.bot.wait_for.assert_has_awaits(
(
- call('message_edit', check=partial_mock(snekbox.predicate_eval_message_edit, ctx), timeout=10),
+ call(
+ 'message_edit',
+ check=partial_mock(snekbox.predicate_eval_message_edit, ctx),
+ timeout=snekbox.REEVAL_TIMEOUT,
+ ),
call('reaction_add', check=partial_mock(snekbox.predicate_eval_emoji_reaction, ctx), timeout=10)
)
)