feature (sponsors): Add sponsor command.
Add new sponsor prompts. Add new sponsor command. Add `sponsor_text` table. Add sponsor global config settings. Update `Setting.command` to use new `widget`. Add custom `cmd_str` support to `Message` `SettingType`.
This commit is contained in:
@@ -13,3 +13,4 @@ from .renting import *
|
|||||||
from .moderation import *
|
from .moderation import *
|
||||||
from .accountability import *
|
from .accountability import *
|
||||||
from .plugins import *
|
from .plugins import *
|
||||||
|
from .sponsors import *
|
||||||
|
|||||||
5
bot/modules/sponsors/__init__.py
Normal file
5
bot/modules/sponsors/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from . import module
|
||||||
|
|
||||||
|
from . import data
|
||||||
|
from . import config
|
||||||
|
from . import commands
|
||||||
27
bot/modules/sponsors/commands.py
Normal file
27
bot/modules/sponsors/commands.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from cmdClient.checks import is_owner
|
||||||
|
|
||||||
|
from .module import module
|
||||||
|
from .config import settings
|
||||||
|
|
||||||
|
|
||||||
|
@module.cmd(
|
||||||
|
name="sponsors",
|
||||||
|
group="Meta",
|
||||||
|
desc="Check out our wonderful partners!",
|
||||||
|
flags=('edit', 'prompt')
|
||||||
|
)
|
||||||
|
async def cmd_sponsors(ctx, flags):
|
||||||
|
"""
|
||||||
|
Usage``:
|
||||||
|
{prefix}sponsors
|
||||||
|
"""
|
||||||
|
if await is_owner.run(ctx) and any(flags.values()):
|
||||||
|
if flags['edit']:
|
||||||
|
# Run edit setting command
|
||||||
|
await settings.sponsor_message.command(ctx, 0)
|
||||||
|
elif flags['prompt']:
|
||||||
|
# Run prompt setting command
|
||||||
|
await settings.sponsor_prompt.command(ctx, 0)
|
||||||
|
else:
|
||||||
|
# Display message
|
||||||
|
await ctx.reply(**settings.sponsor_message.args(ctx))
|
||||||
70
bot/modules/sponsors/config.py
Normal file
70
bot/modules/sponsors/config.py
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
from cmdClient.checks import is_owner
|
||||||
|
|
||||||
|
from settings.base import Setting, ColumnData, ObjectSettings
|
||||||
|
from settings.setting_types import Message, String
|
||||||
|
|
||||||
|
from meta import client
|
||||||
|
from utils.lib import DotDict
|
||||||
|
|
||||||
|
from .data import sponsor_text
|
||||||
|
|
||||||
|
|
||||||
|
class SponsorSettings(ObjectSettings):
|
||||||
|
settings = DotDict()
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@SponsorSettings.attach_setting
|
||||||
|
class sponsor_prompt(String, ColumnData, Setting):
|
||||||
|
attr_name = 'sponsor_prompt'
|
||||||
|
_default = "Type {prefix}sponsors to check our wonderful partners!"
|
||||||
|
|
||||||
|
write_ward = is_owner
|
||||||
|
|
||||||
|
display_name = 'sponsor_prompt'
|
||||||
|
desc = "Text to send after core commands to encourage checking `sponsors`."
|
||||||
|
long_desc = (
|
||||||
|
"Text posted after several commands to encourage users to check the `sponsors` command. "
|
||||||
|
"Occurences of `{{prefix}}` will be replaced by the bot prefix."
|
||||||
|
)
|
||||||
|
|
||||||
|
_quote = False
|
||||||
|
|
||||||
|
_data_column = 'prompt_text'
|
||||||
|
_table_interface = sponsor_text
|
||||||
|
_id_column = 'ID'
|
||||||
|
_upsert = True
|
||||||
|
_create_row = True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _data_to_value(cls, id, data, **kwargs):
|
||||||
|
if data:
|
||||||
|
return data.replace("{prefix}", client.prefix)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@SponsorSettings.attach_setting
|
||||||
|
class sponsor_message(Message, ColumnData, Setting):
|
||||||
|
attr_name = 'sponsor_message'
|
||||||
|
_default = '{"content": "Coming Soon!"}'
|
||||||
|
|
||||||
|
write_ward = is_owner
|
||||||
|
|
||||||
|
display_name = 'sponsor_message'
|
||||||
|
desc = "`sponsors` command response."
|
||||||
|
|
||||||
|
long_desc = (
|
||||||
|
"Message to reply with when a user runs the `sponsors` command."
|
||||||
|
)
|
||||||
|
|
||||||
|
_data_column = 'command_response'
|
||||||
|
_table_interface = sponsor_text
|
||||||
|
_id_column = 'ID'
|
||||||
|
_upsert = True
|
||||||
|
_create_row = True
|
||||||
|
|
||||||
|
_cmd_str = "{prefix}sponsors --edit"
|
||||||
|
|
||||||
|
|
||||||
|
settings = SponsorSettings(0)
|
||||||
4
bot/modules/sponsors/data.py
Normal file
4
bot/modules/sponsors/data.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from data import Table
|
||||||
|
|
||||||
|
|
||||||
|
sponsor_text = Table("sponsor_text")
|
||||||
27
bot/modules/sponsors/module.py
Normal file
27
bot/modules/sponsors/module.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import discord
|
||||||
|
|
||||||
|
from LionModule import LionModule
|
||||||
|
from LionContext import LionContext
|
||||||
|
|
||||||
|
from meta import client
|
||||||
|
|
||||||
|
from .config import settings
|
||||||
|
|
||||||
|
|
||||||
|
module = LionModule("Sponsor")
|
||||||
|
|
||||||
|
|
||||||
|
sponsored_commands = {'profile', 'stats', 'weekly', 'monthly'}
|
||||||
|
|
||||||
|
|
||||||
|
@LionContext.reply.add_wrapper
|
||||||
|
async def sponsor_reply_wrapper(func, ctx: LionContext, *args, **kwargs):
|
||||||
|
if ctx.cmd and ctx.cmd.name in sponsored_commands:
|
||||||
|
sponsor_hint = discord.Embed(
|
||||||
|
description=settings.sponsor_prompt.value,
|
||||||
|
colour=discord.Colour.dark_theme()
|
||||||
|
)
|
||||||
|
if 'embed' not in kwargs:
|
||||||
|
kwargs['embed'] = sponsor_hint
|
||||||
|
|
||||||
|
return await func(ctx, *args, **kwargs)
|
||||||
@@ -2,6 +2,8 @@ from LionModule import LionModule
|
|||||||
from LionContext import LionContext
|
from LionContext import LionContext
|
||||||
from core.lion import Lion
|
from core.lion import Lion
|
||||||
|
|
||||||
|
from modules.sponsors.module import sponsored_commands
|
||||||
|
|
||||||
from .utils import get_last_voted_timestamp, lion_loveemote, lion_yayemote
|
from .utils import get_last_voted_timestamp, lion_loveemote, lion_yayemote
|
||||||
from .webhook import init_webhook
|
from .webhook import init_webhook
|
||||||
|
|
||||||
@@ -39,12 +41,14 @@ boostfree_commands = {'config', 'pomodoro'}
|
|||||||
async def topgg_reply_wrapper(func, ctx: LionContext, *args, suggest_vote=True, **kwargs):
|
async def topgg_reply_wrapper(func, ctx: LionContext, *args, suggest_vote=True, **kwargs):
|
||||||
if not suggest_vote:
|
if not suggest_vote:
|
||||||
pass
|
pass
|
||||||
elif ctx.cmd and (ctx.cmd.name in boostfree_commands or ctx.cmd.group in boostfree_groups):
|
elif not ctx.cmd:
|
||||||
|
pass
|
||||||
|
elif ctx.cmd.name in boostfree_commands or ctx.cmd.group in boostfree_groups:
|
||||||
pass
|
pass
|
||||||
elif not get_last_voted_timestamp(ctx.author.id):
|
elif not get_last_voted_timestamp(ctx.author.id):
|
||||||
upvote_info_formatted = upvote_info.format(lion_yayemote, ctx.best_prefix, lion_loveemote)
|
upvote_info_formatted = upvote_info.format(lion_yayemote, ctx.best_prefix, lion_loveemote)
|
||||||
|
|
||||||
if 'embed' in kwargs:
|
if 'embed' in kwargs and ctx.cmd.name not in sponsored_commands:
|
||||||
# Add message as an extra embed field
|
# Add message as an extra embed field
|
||||||
kwargs['embed'].add_field(
|
kwargs['embed'].add_field(
|
||||||
name="\u200b",
|
name="\u200b",
|
||||||
|
|||||||
@@ -201,13 +201,13 @@ class Setting:
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def command(cls, ctx, id):
|
async def command(cls, ctx, id, flags=()):
|
||||||
"""
|
"""
|
||||||
Standardised command viewing/setting interface for the setting.
|
Standardised command viewing/setting interface for the setting.
|
||||||
"""
|
"""
|
||||||
if not ctx.args:
|
if not ctx.args and not ctx.msg.attachments:
|
||||||
# View config embed for provided cls
|
# View config embed for provided cls
|
||||||
await ctx.reply(embed=cls.get(id).embed)
|
await cls.get(id).widget(ctx, flags=flags)
|
||||||
else:
|
else:
|
||||||
# Check the write ward
|
# Check the write ward
|
||||||
if cls.write_ward and not await cls.write_ward.run(ctx):
|
if cls.write_ward and not await cls.write_ward.run(ctx):
|
||||||
|
|||||||
@@ -713,6 +713,8 @@ class Message(SettingType):
|
|||||||
_substitution_desc = {
|
_substitution_desc = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_cmd_str = '{prefix} config {setting}'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _data_from_value(cls, id, value, **kwargs):
|
def _data_from_value(cls, id, value, **kwargs):
|
||||||
if value is None:
|
if value is None:
|
||||||
@@ -844,14 +846,16 @@ class Message(SettingType):
|
|||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Setting Guide",
|
name="Setting Guide",
|
||||||
value=(
|
value=(
|
||||||
"• For plain text without an embed, use `{prefix}config {setting} <text>`.\n"
|
"• For plain text without an embed, use `{cmd_str} <text>`.\n"
|
||||||
"• To include an embed, build the message [here]({builder}) "
|
"• To include an embed, build the message [here]({builder}) "
|
||||||
"and upload the json code as a file with the `{prefix}config {setting}` command.\n"
|
"and upload the json code as a file with the `{cmd_str}` command.\n"
|
||||||
"• To reset the message to the default, use `{prefix}config {setting} None`."
|
"• To reset the message to the default, use `{cmd_str} None`."
|
||||||
|
).format(
|
||||||
|
cmd_str=self._cmd_str,
|
||||||
|
builder="https://glitchii.github.io/embedbuilder/?editor=gui"
|
||||||
).format(
|
).format(
|
||||||
prefix=ctx.best_prefix,
|
prefix=ctx.best_prefix,
|
||||||
setting=self.display_name,
|
setting=self.display_name,
|
||||||
builder="https://glitchii.github.io/embedbuilder/?editor=gui"
|
|
||||||
),
|
),
|
||||||
inline=False
|
inline=False
|
||||||
)
|
)
|
||||||
|
|||||||
9
data/migration/v10-v11/migration.sql
Normal file
9
data/migration/v10-v11/migration.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
-- Sponsor Data {{{
|
||||||
|
CREATE TABLE sponsor_text(
|
||||||
|
ID INTEGER PRIMARY KEY DEFAULT 0,
|
||||||
|
prompt_text TEXT,
|
||||||
|
command_response TEXT
|
||||||
|
);
|
||||||
|
-- }}}
|
||||||
|
|
||||||
|
INSERT INTO VersionHistory (version, author) VALUES (11, 'v10-v11 migration');
|
||||||
@@ -4,7 +4,7 @@ CREATE TABLE VersionHistory(
|
|||||||
time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
author TEXT
|
author TEXT
|
||||||
);
|
);
|
||||||
INSERT INTO VersionHistory (version, author) VALUES (10, 'Initial Creation');
|
INSERT INTO VersionHistory (version, author) VALUES (11, 'Initial Creation');
|
||||||
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION update_timestamp_column()
|
CREATE OR REPLACE FUNCTION update_timestamp_column()
|
||||||
@@ -38,6 +38,15 @@ CREATE TABLE global_guild_blacklist(
|
|||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
-- Sponsor Data {{{
|
||||||
|
CREATE TABLE sponsor_text(
|
||||||
|
ID INTEGER PRIMARY KEY DEFAULT 0,
|
||||||
|
prompt_text TEXT,
|
||||||
|
command_response TEXT
|
||||||
|
);
|
||||||
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
-- User configuration data {{{
|
-- User configuration data {{{
|
||||||
CREATE TABLE user_config(
|
CREATE TABLE user_config(
|
||||||
userid BIGINT PRIMARY KEY,
|
userid BIGINT PRIMARY KEY,
|
||||||
|
|||||||
Reference in New Issue
Block a user