mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-05 17:02:32 -05:00
[V3 Config] Adjust functionality of get_attr (#1342)
* Intermediate commit * Add defaulting stuff to config * Remove set_attr in favor of set_raw * Modify get_attr * Fix issue with clearing data
This commit is contained in:
@@ -70,7 +70,7 @@ class CommandObj:
|
||||
async def get(self,
|
||||
message: discord.Message,
|
||||
command: str) -> str:
|
||||
ccinfo = await self.db(message.guild).commands.get_attr(command)
|
||||
ccinfo = await self.db(message.guild).commands.get_raw(command, default=None)
|
||||
if not ccinfo:
|
||||
raise NotFound
|
||||
else:
|
||||
@@ -82,7 +82,7 @@ class CommandObj:
|
||||
response):
|
||||
"""Create a customcommand"""
|
||||
# Check if this command is already registered as a customcommand
|
||||
if await self.db(ctx.guild).commands.get_attr(command):
|
||||
if await self.db(ctx.guild).commands.get_raw(command, default=None):
|
||||
raise AlreadyExists()
|
||||
author = ctx.message.author
|
||||
ccinfo = {
|
||||
@@ -96,8 +96,8 @@ class CommandObj:
|
||||
'response': response
|
||||
|
||||
}
|
||||
await self.db(ctx.guild).commands.set_attr(command,
|
||||
ccinfo)
|
||||
await self.db(ctx.guild).commands.set_raw(
|
||||
command, value=ccinfo)
|
||||
|
||||
async def edit(self,
|
||||
ctx: commands.Context,
|
||||
@@ -105,11 +105,11 @@ class CommandObj:
|
||||
response: None):
|
||||
"""Edit an already existing custom command"""
|
||||
# Check if this command is registered
|
||||
if not await self.db(ctx.guild).commands.get_attr(command):
|
||||
if not await self.db(ctx.guild).commands.get_raw(command, default=None):
|
||||
raise NotFound()
|
||||
|
||||
author = ctx.message.author
|
||||
ccinfo = await self.db(ctx.guild).commands.get_attr(command)
|
||||
ccinfo = await self.db(ctx.guild).commands.get_raw(command, default=None)
|
||||
|
||||
def check(m):
|
||||
return m.channel == ctx.channel and m.author == ctx.message.author
|
||||
@@ -138,18 +138,18 @@ class CommandObj:
|
||||
author.id
|
||||
)
|
||||
|
||||
await self.db(ctx.guild).commands.set_attr(command,
|
||||
ccinfo)
|
||||
await self.db(ctx.guild).commands.set_raw(
|
||||
command, value=ccinfo)
|
||||
|
||||
async def delete(self,
|
||||
ctx: commands.Context,
|
||||
command: str):
|
||||
"""Delete an already exisiting custom command"""
|
||||
# Check if this command is registered
|
||||
if not await self.db(ctx.guild).commands.get_attr(command):
|
||||
if not await self.db(ctx.guild).commands.get_raw(command, default=None):
|
||||
raise NotFound()
|
||||
await self.db(ctx.guild).commands.set_attr(command,
|
||||
None)
|
||||
await self.db(ctx.guild).commands.set_raw(
|
||||
command, value=None)
|
||||
|
||||
|
||||
class CustomCommands:
|
||||
@@ -326,7 +326,7 @@ class CustomCommands:
|
||||
return
|
||||
|
||||
guild = message.guild
|
||||
prefixes = await self.bot.db.guild(message.guild).get_attr('prefix')
|
||||
prefixes = await self.bot.db.guild(guild).get_raw('prefix', default=[])
|
||||
|
||||
if len(prefixes) < 1:
|
||||
def_prefixes = await self.bot.get_prefix(message)
|
||||
|
||||
@@ -53,7 +53,7 @@ class Streams:
|
||||
@commands.command()
|
||||
async def twitch(self, ctx, channel_name: str):
|
||||
"""Checks if a Twitch channel is streaming"""
|
||||
token = await self.db.tokens.get_attr(TwitchStream.__name__)
|
||||
token = await self.db.tokens.get_raw(TwitchStream.__name__, default=None)
|
||||
stream = TwitchStream(name=channel_name,
|
||||
token=token)
|
||||
await self.check_online(ctx, stream)
|
||||
@@ -187,7 +187,7 @@ class Streams:
|
||||
async def stream_alert(self, ctx, _class, channel_name):
|
||||
stream = self.get_stream(_class, channel_name.lower())
|
||||
if not stream:
|
||||
token = await self.db.tokens.get_attr(_class.__name__)
|
||||
token = await self.db.tokens.get_raw(_class.__name__, default=None)
|
||||
stream = _class(name=channel_name,
|
||||
token=token)
|
||||
try:
|
||||
@@ -210,7 +210,7 @@ class Streams:
|
||||
async def community_alert(self, ctx, _class, community_name):
|
||||
community = self.get_community(_class, community_name)
|
||||
if not community:
|
||||
token = await self.db.tokens.get_attr(_class.__name__)
|
||||
token = await self.db.tokens.get_raw(_class.__name__, default=None)
|
||||
community = _class(name=community_name, token=token)
|
||||
try:
|
||||
await community.get_community_streams()
|
||||
@@ -477,7 +477,7 @@ class Streams:
|
||||
if not _class:
|
||||
continue
|
||||
|
||||
token = await self.db.tokens.get_attr(_class.__name__)
|
||||
token = await self.db.tokens.get_raw(_class.__name__)
|
||||
streams.append(_class(token=token, **raw_stream))
|
||||
|
||||
# issue 1191 extended resolution: Remove this after suitable period
|
||||
@@ -497,7 +497,7 @@ class Streams:
|
||||
if not _class:
|
||||
continue
|
||||
|
||||
token = await self.db.tokens.get_attr(_class.__name__)
|
||||
token = await self.db.tokens.get_raw(_class.__name__, default=None)
|
||||
communities.append(_class(token=token, **raw_community))
|
||||
|
||||
# issue 1191 extended resolution: Remove this after suitable period
|
||||
|
||||
Reference in New Issue
Block a user