Use correct prefixes when sending messages to owners (#3632)

* use correct prefixes when sending messages to owners

* make internal util for this instead

* oops

* fix circular import

* let's add back the actual fix I made this PR for...

* fix wrong logger name

* improve log message
This commit is contained in:
jack1142
2020-03-12 17:31:33 +01:00
committed by GitHub
parent 3ff127d514
commit 4afe1ff569
4 changed files with 89 additions and 31 deletions

View File

@@ -1,4 +1,5 @@
import asyncio
import logging
import re
from abc import ABC
from collections import defaultdict
@@ -8,6 +9,7 @@ import discord
from redbot.core import Config, modlog, commands
from redbot.core.bot import Red
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils._internal_utils import send_to_owners_with_prefix_replaced
from .casetypes import CASETYPES
from .events import Events
from .kickban import KickBanMixin
@@ -104,14 +106,12 @@ class Mod(
await self.settings.guild(discord.Object(id=guild_id)).delete_repeats.set(val)
await self.settings.version.set("1.0.0") # set version of last update
if await self.settings.version() < "1.1.0":
prefixes = await self.bot.get_valid_prefixes()
prefix = re.sub(rf"<@!?{self.bot.user.id}>", f"@{self.bot.user.name}", prefixes[0])
msg = _(
"Ignored guilds and channels have been moved. "
"Please use `{prefix}moveignoredchannels` if "
"Please use `[p]moveignoredchannels` if "
"you were previously using these functions."
).format(prefix=prefix)
self.bot.loop.create_task(self.bot.send_to_owners(msg))
)
self.bot.loop.create_task(send_to_owners_with_prefix_replaced(self.bot, msg))
await self.settings.version.set(__version__)
@commands.command()

View File

@@ -2,6 +2,7 @@ import discord
from redbot.core.bot import Red
from redbot.core import checks, commands, Config
from redbot.core.i18n import cog_i18n, Translator
from redbot.core.utils._internal_utils import send_to_owners_with_prefix_replaced
from redbot.core.utils.chat_formatting import escape, pagify
from .streamtypes import (
@@ -111,8 +112,6 @@ class Streams(commands.Cog):
try:
tokens["client_secret"]
except KeyError:
prefixes = await self.bot.get_valid_prefixes()
prefix = re.sub(rf"<@!?{self.bot.user.id}>", f"@{self.bot.user.name}", prefixes[0])
message = _(
"You need a client secret key to use correctly Twitch API on this cog.\n"
"Follow these steps:\n"
@@ -120,12 +119,12 @@ class Streams(commands.Cog):
'2. Click "Manage" on your application.\n'
'3. Click on "New secret".\n'
"5. Copy your client ID and your client secret into:\n"
"`{prefix}set api twitch client_id <your_client_id_here> "
"`[p]set api twitch client_id <your_client_id_here> "
"client_secret <your_client_secret_here>`\n\n"
"Note: These tokens are sensitive and should only be used in a private channel "
"or in DM with the bot."
).format(prefix=prefix)
await self.bot.send_to_owners(message)
)
await send_to_owners_with_prefix_replaced(self.bot, message)
async with aiohttp.ClientSession() as session:
async with session.post(
"https://id.twitch.tv/oauth2/token",