feature (sponsors): Add guild whitelist.
Add `sponsor_hidden_in` app setting. Add new `GuildID` and `GuildIDList` setting types.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
from cmdClient.checks import is_owner
|
||||
|
||||
from settings import AppSettings, Setting, KeyValueData, ListData
|
||||
from settings.setting_types import Message, String
|
||||
from settings.setting_types import Message, String, GuildIDList
|
||||
|
||||
from meta import client
|
||||
from core.data import app_config
|
||||
|
||||
from .data import guild_whitelist
|
||||
|
||||
@AppSettings.attach_setting
|
||||
class sponsor_prompt(String, KeyValueData, Setting):
|
||||
@@ -37,6 +38,13 @@ class sponsor_prompt(String, KeyValueData, Setting):
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def success_response(self):
|
||||
if self.value:
|
||||
return "The sponsor prompt has been update."
|
||||
else:
|
||||
return "The sponsor prompt has been cleared."
|
||||
|
||||
|
||||
@AppSettings.attach_setting
|
||||
class sponsor_message(Message, KeyValueData, Setting):
|
||||
@@ -60,3 +68,25 @@ class sponsor_message(Message, KeyValueData, Setting):
|
||||
_key = 'sponsor_message'
|
||||
|
||||
_cmd_str = "{prefix}sponsors --edit"
|
||||
|
||||
@property
|
||||
def success_response(self):
|
||||
return "The `sponsors` command message has been updated."
|
||||
|
||||
|
||||
@AppSettings.attach_setting
|
||||
class sponsor_guild_whitelist(GuildIDList, ListData, Setting):
|
||||
attr_name = 'sponsor_guild_whitelist'
|
||||
write_ward = is_owner
|
||||
|
||||
category = 'Sponsors'
|
||||
display_name = 'sponsor_hidden_in'
|
||||
desc = "Guilds where the sponsor prompt is not displayed."
|
||||
long_desc = (
|
||||
"A list of guilds where the sponsor prompt hint will be hidden (see the `sponsor_prompt` setting)."
|
||||
)
|
||||
|
||||
_table_interface = guild_whitelist
|
||||
_id_column = 'appid'
|
||||
_data_column = 'guildid'
|
||||
_force_unique = True
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from data import Table
|
||||
|
||||
|
||||
sponsor_text = Table("sponsor_text")
|
||||
guild_whitelist = Table("sponsor_guild_whitelist")
|
||||
|
||||
@@ -16,11 +16,12 @@ sponsored_commands = {'profile', 'stats', 'weekly', 'monthly'}
|
||||
async def sponsor_reply_wrapper(func, ctx: LionContext, *args, **kwargs):
|
||||
if ctx.cmd and ctx.cmd.name in sponsored_commands:
|
||||
if (prompt := ctx.client.settings.sponsor_prompt.value):
|
||||
sponsor_hint = discord.Embed(
|
||||
description=prompt,
|
||||
colour=discord.Colour.dark_theme()
|
||||
)
|
||||
if 'embed' not in kwargs:
|
||||
kwargs['embed'] = sponsor_hint
|
||||
if not ctx.guild or ctx.guild.id not in ctx.client.settings.sponsor_guild_whitelist.value:
|
||||
sponsor_hint = discord.Embed(
|
||||
description=prompt,
|
||||
colour=discord.Colour.dark_theme()
|
||||
)
|
||||
if 'embed' not in kwargs:
|
||||
kwargs['embed'] = sponsor_hint
|
||||
|
||||
return await func(ctx, *args, **kwargs)
|
||||
|
||||
@@ -473,6 +473,64 @@ class Emoji(SettingType):
|
||||
return str(data)
|
||||
|
||||
|
||||
class GuildID(SettingType):
|
||||
"""
|
||||
Integer type for storing Guild IDs. Stores any snowflake.
|
||||
|
||||
Types:
|
||||
data: Optional[int]
|
||||
The stored integer value.
|
||||
value: Optional[int]
|
||||
The stored integer value.
|
||||
"""
|
||||
accepts = "Any snowflake id."
|
||||
|
||||
@classmethod
|
||||
def _data_from_value(cls, id: int, value: Optional[bool], **kwargs):
|
||||
"""
|
||||
Both data and value are of type Optional[int].
|
||||
Directly return the provided value as data.
|
||||
"""
|
||||
return value
|
||||
|
||||
@classmethod
|
||||
def _data_to_value(cls, id: int, data: Optional[bool], **kwargs):
|
||||
"""
|
||||
Both data and value are of type Optional[int].
|
||||
Directly return the internal data as the value.
|
||||
"""
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
async def _parse_userstr(cls, ctx: Context, id: int, userstr: str, **kwargs):
|
||||
"""
|
||||
Relies on integer casting to convert the user string
|
||||
"""
|
||||
if not userstr or userstr.lower() == "none":
|
||||
return None
|
||||
|
||||
try:
|
||||
num = int(userstr)
|
||||
except Exception:
|
||||
raise UserInputError("Couldn't parse provided guild id.") from None
|
||||
|
||||
return num
|
||||
|
||||
@classmethod
|
||||
def _format_data(cls, id: int, data: Optional[int], **kwargs):
|
||||
"""
|
||||
Return the string version of the data.
|
||||
"""
|
||||
if data is None:
|
||||
return None
|
||||
elif (guild := client.get_guild(data)):
|
||||
return f"`{data}` ({guild.name})"
|
||||
elif (row := client.data.guild_config.fetch(data)):
|
||||
return f"`{data}` ({row.name})"
|
||||
else:
|
||||
return f"`{data}`"
|
||||
|
||||
|
||||
class Timezone(SettingType):
|
||||
"""
|
||||
Timezone type, storing a valid timezone string.
|
||||
@@ -1046,3 +1104,16 @@ class StringList(SettingList):
|
||||
"Write `--add` or `--remove` to add or remove strings."
|
||||
)
|
||||
_setting = String
|
||||
|
||||
|
||||
class GuildIDList(SettingList):
|
||||
"""
|
||||
List of guildids.
|
||||
"""
|
||||
accepts = (
|
||||
"Comma separated list of guild ids. Use `None` to unset. "
|
||||
"Write `--add` or `--remove` to add or remove ids. "
|
||||
"The provided ids are not verified in any way."
|
||||
)
|
||||
|
||||
_setting = GuildID
|
||||
|
||||
@@ -10,13 +10,17 @@ CREATE TABLE AppConfig(
|
||||
|
||||
-- Sponsor Data {{{
|
||||
CREATE TABLE sponsor_guild_whitelist(
|
||||
guildid INTEGER PRIMARY KEY
|
||||
appid TEXT,
|
||||
guildid BIGINT,
|
||||
PRIMARY KEY(appid, guildid)
|
||||
);
|
||||
-- }}}
|
||||
|
||||
-- Topgg Data {{{
|
||||
CREATE TABLE topgg_guild_whitelist(
|
||||
guildid INTEGER PRIMARY KEY
|
||||
appid TEXT,
|
||||
guildid BIGINT,
|
||||
PRIMARY KEY(appid, guildid)
|
||||
);
|
||||
-- }}}
|
||||
|
||||
|
||||
@@ -807,13 +807,17 @@ create TABLE topgg(
|
||||
CREATE INDEX topgg_userid_timestamp ON topgg (userid, boostedTimestamp);
|
||||
|
||||
CREATE TABLE topgg_guild_whitelist(
|
||||
guildid INTEGER PRIMARY KEY
|
||||
appid TEXT,
|
||||
guildid BIGINT,
|
||||
PRIMARY KEY(appid, guildid)
|
||||
);
|
||||
-- }}}
|
||||
|
||||
-- Sponsor Data {{{
|
||||
CREATE TABLE sponsor_guild_whitelist(
|
||||
guildid INTEGER PRIMARY KEY
|
||||
appid TEXT,
|
||||
guildid BIGINT,
|
||||
PRIMARY KEY(appid, guildid)
|
||||
);
|
||||
-- }}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user