Skip to content

Commit

Permalink
begin more work on settings v2
Browse files Browse the repository at this point in the history
  • Loading branch information
www committed Nov 20, 2024
1 parent 4b6d718 commit c36715e
Show file tree
Hide file tree
Showing 25 changed files with 211 additions and 5,068 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/rust.bot_modules.core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl silverpelt::module::Module for Module {
]
}

fn config_options(&self) -> Vec<module_settings::types::ConfigOption> {
fn config_options(&self) -> Vec<module_settings::types::Setting> {
vec![
(*settings::GUILD_ROLES).clone(),
(*settings::GUILD_MEMBERS).clone(),
Expand Down
26 changes: 13 additions & 13 deletions core/rust.bot_modules.core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ use module_settings::types::SettingsData;
use module_settings::{
data_stores::{PostgresDataStore, PostgresDataStoreImpl},
types::{
settings_wrap, Column, ColumnSuggestion, ColumnType, ConfigOption, HookContext,
settings_wrap, Column, ColumnSuggestion, ColumnType, Setting, HookContext,
InnerColumnType, InnerColumnTypeStringKind, OperationSpecific, OperationType, PostAction,
SettingDataValidator, SettingsError, NoOpPostAction, NoOpValidator
},
};
use splashcore_rs::value::Value;
use std::sync::LazyLock;

pub static GUILD_ROLES: LazyLock<ConfigOption> = LazyLock::new(|| {
ConfigOption {
pub static GUILD_ROLES: LazyLock<Setting> = LazyLock::new(|| {
Setting {
id: "guild_roles",
name: "Server Roles",
description: "Configure/setup server roles which can then have permissions on AntiRaid",
Expand Down Expand Up @@ -551,8 +551,8 @@ impl PostAction for GuildRolesPostAction {
}
}

pub static GUILD_MEMBERS: LazyLock<ConfigOption> = LazyLock::new(|| {
ConfigOption {
pub static GUILD_MEMBERS: LazyLock<Setting> = LazyLock::new(|| {
Setting {
id: "guild_members",
name: "Server Members",
description: "Manage server members",
Expand Down Expand Up @@ -924,8 +924,8 @@ impl SettingDataValidator for GuildMembersValidator {
}
}

pub static GUILD_TEMPLATES: LazyLock<ConfigOption> = LazyLock::new(|| {
ConfigOption {
pub static GUILD_TEMPLATES: LazyLock<Setting> = LazyLock::new(|| {
Setting {
id: "guild_templates",
name: "Server Templates",
description: "Configure/Setup Server Templates (Lua/Roblox Luau scripts)",
Expand Down Expand Up @@ -1117,8 +1117,8 @@ impl PostAction for GuildTemplatePostAction {
}
}

pub static GUILD_TEMPLATES_KV: LazyLock<ConfigOption> = LazyLock::new(|| {
ConfigOption {
pub static GUILD_TEMPLATES_KV: LazyLock<Setting> = LazyLock::new(|| {
Setting {
id: "guild_templates_kv",
name: "Server Templates (key-value db)",
description: "Key-value database available to templates on this server",
Expand Down Expand Up @@ -1192,8 +1192,8 @@ pub static GUILD_TEMPLATES_KV: LazyLock<ConfigOption> = LazyLock::new(|| {
}
});

pub static GUILD_TEMPLATE_SHOP: LazyLock<ConfigOption> = LazyLock::new(|| {
ConfigOption {
pub static GUILD_TEMPLATE_SHOP: LazyLock<Setting> = LazyLock::new(|| {
Setting {
id: "template_shop",
name: "Created/Published Templates",
description: "Publish new templates to the shop that can be used by any other server",
Expand Down Expand Up @@ -1340,8 +1340,8 @@ pub static GUILD_TEMPLATE_SHOP: LazyLock<ConfigOption> = LazyLock::new(|| {
}
});

pub static GUILD_TEMPLATE_SHOP_PUBLIC_LIST: LazyLock<ConfigOption> = LazyLock::new(|| {
ConfigOption {
pub static GUILD_TEMPLATE_SHOP_PUBLIC_LIST: LazyLock<Setting> = LazyLock::new(|| {
Setting {
id: "template_shop_public_list",
name: "Explore the shop!",
description: "Explore other templates published by other servers",
Expand Down
6 changes: 1 addition & 5 deletions core/rust.bot_modules.lockdown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl silverpelt::module::Module for Module {
"Lockdown module for quickly locking/unlocking your whole server or individual channels"
}

fn config_options(&self) -> Vec<module_settings::types::ConfigOption> {
fn config_options(&self) -> Vec<module_settings::types::Setting> {
vec![
(*settings::LOCKDOWN_SETTINGS).clone(),
(*settings::LOCKDOWNS).clone(),
Expand All @@ -37,8 +37,4 @@ impl silverpelt::module::Module for Module {
},
)]
}

fn full_command_list(&self) -> Vec<silverpelt::module::CommandObj> {
modules_ext::create_full_command_list(self)
}
}
147 changes: 45 additions & 102 deletions core/rust.bot_modules.lockdown/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,118 +2,77 @@ use async_trait::async_trait;
use module_settings::{
data_stores::{PostgresDataStore, PostgresDataStoreImpl},
types::{
settings_wrap, Column, ColumnSuggestion, ColumnType, ConfigOption,
settings_wrap, Column, ColumnSuggestion, ColumnType, Setting,
CreateDataStore, DataStore, InnerColumnType, InnerColumnTypeStringKind, OperationSpecific,
OperationType, SettingsData, SettingsError, NoOpValidator, NoOpPostAction,
},
};
use splashcore_rs::value::Value;
use std::sync::LazyLock;

pub static LOCKDOWN_SETTINGS: LazyLock<ConfigOption> = LazyLock::new(|| {
ConfigOption {
id: "lockdown_guilds",
name: "Lockdown Settings",
description: "Setup standard lockdown settings for a server",
table: "lockdown__guilds",
common_filters: indexmap::indexmap! {},
default_common_filters: indexmap::indexmap! {
"guild_id" => "{__guild_id}"
},
primary_key: "guild_id",
max_entries: Some(1),
max_return: 2,
data_store: settings_wrap(PostgresDataStore {}),
pub static LOCKDOWN_SETTINGS: LazyLock<Setting> = LazyLock::new(|| {
Setting {
id: "lockdown_guilds".to_string(),
name: "Lockdown Settings".to_string(),
description: "Setup standard lockdown settings for a server".to_string(),
primary_key: "guild_id".to_string(),
columns: settings_wrap(vec![
module_settings::common_columns::guild_id(
"guild_id",
"Guild ID",
"Guild ID of the server in question",
),
Column {
id: "member_roles",
name: "Member Roles",
description: "Which roles to use as member roles for the purpose of lockdown. These roles will be explicitly modified during lockdown",
id: "member_roles".to_string(),
name: "Member Roles".to_string(),
description: "Which roles to use as member roles for the purpose of lockdown. These roles will be explicitly modified during lockdown".to_string(),
column_type: ColumnType::new_array(InnerColumnType::String {
kind: InnerColumnTypeStringKind::Role,
min_length: None,
max_length: None,
allowed_values: vec![],
}),
nullable: false,
default: None,
unique: false,
suggestions: ColumnSuggestion::None {},
ignored_for: vec![],
secret: false,
},
Column {
id: "require_correct_layout",
name: "Require Correct Layout",
description: "Whether or not a lockdown can proceed even without correct critical role permissions. May lead to partial lockdowns if disabled",
id: "require_correct_layout".to_string(),
name: "Require Correct Layout".to_string(),
description: "Whether or not a lockdown can proceed even without correct critical role permissions. May lead to partial lockdowns if disabled".to_string(),
column_type: ColumnType::new_scalar(InnerColumnType::Boolean {}),
nullable: false,
default: None,
unique: true,
suggestions: ColumnSuggestion::None {},
ignored_for: vec![OperationType::Create],
ignored_for: vec![],
secret: false,
},
module_settings::common_columns::created_at(),
module_settings::common_columns::created_by(),
module_settings::common_columns::last_updated_at(),
module_settings::common_columns::last_updated_by(),
]),
title_template: "Lockdown Settings",
operations: indexmap::indexmap! {
OperationType::View => OperationSpecific {
columns_to_set: indexmap::indexmap! {},
},
OperationType::Create => OperationSpecific {
columns_to_set: indexmap::indexmap! {
"created_at" => "{__now}",
"created_by" => "{__author}",
"last_updated_at" => "{__now}",
"last_updated_by" => "{__author}",
},
},
OperationType::Update => OperationSpecific {
columns_to_set: indexmap::indexmap! {
"last_updated_at" => "{__now}",
"last_updated_by" => "{__author}",
},
},
OperationType::Delete => OperationSpecific {
columns_to_set: indexmap::indexmap! {},
},
},
validator: settings_wrap(NoOpValidator {}),
post_action: settings_wrap(NoOpPostAction {}),
title_template: "Lockdown Settings".to_string(),
supported_operations: vec![
OperationType::View,
OperationType::Save,
OperationType::Delete,
],
}
});

pub static LOCKDOWNS: LazyLock<ConfigOption> = LazyLock::new(|| ConfigOption {
id: "lockdowns",
name: "Lockdowns",
description: "Lockdowns",
table: "lockdown__guild_lockdowns",
common_filters: indexmap::indexmap! {},
default_common_filters: indexmap::indexmap! {
"guild_id" => "{__guild_id}"
},
primary_key: "id",
max_entries: Some(1),
max_return: 5,
data_store: settings_wrap(LockdownDataStore {}), // We use a custom data store here to make lockdown handling easier+more separate from settings
pub static LOCKDOWNS: LazyLock<Setting> = LazyLock::new(|| Setting {
id: "lockdowns".to_string(),
name: "Lockdowns".to_string(),
description: "Lockdowns".to_string(),
primary_key: "id".to_string(),
columns: settings_wrap(vec![
Column {
id: "id",
name: "ID",
description: "The ID of the lockdown",
id: "id".to_string(),
name: "ID".to_string(),
description: "The ID of the lockdown".to_string(),
column_type: ColumnType::new_scalar(InnerColumnType::Uuid {}),
nullable: false,
default: None,
unique: false,
suggestions: ColumnSuggestion::None {},
ignored_for: vec![OperationType::Create],
secret: false,
Expand All @@ -124,69 +83,53 @@ pub static LOCKDOWNS: LazyLock<ConfigOption> = LazyLock::new(|| ConfigOption {
"The Guild ID referring to this lockdown",
),
Column {
id: "type",
name: "Type",
description: "The type of the lockdown.",
id: "type".to_string(),
name: "Type".to_string(),
description: "The type of the lockdown.".to_string(),
column_type: ColumnType::new_scalar(InnerColumnType::String {
kind: InnerColumnTypeStringKind::Normal,
min_length: Some(1),
max_length: Some(256),
allowed_values: vec![],
}),
nullable: false,
default: None,
unique: false,
suggestions: ColumnSuggestion::None {},
ignored_for: vec![],
secret: false,
},
Column {
id: "data",
name: "Data",
description: "The data stored of the lockdown.",
id: "data".to_string(),
name: "Data".to_string(),
description: "The data stored of the lockdown.".to_string(),
column_type: ColumnType::new_scalar(InnerColumnType::Json { max_bytes: None }),
nullable: false,
default: None,
unique: false,
suggestions: ColumnSuggestion::None {},
ignored_for: vec![OperationType::Create],
ignored_for: vec![OperationType::Save],
secret: false,
},
Column {
id: "reason",
name: "Reason",
description: "The reason for starting the lockdown.",
id: "reason".to_string(),
name: "Reason".to_string(),
description: "The reason for starting the lockdown.".to_string(),
column_type: ColumnType::new_scalar(InnerColumnType::String {
kind: InnerColumnTypeStringKind::Normal,
min_length: Some(1),
max_length: Some(256),
allowed_values: vec![],
}),
nullable: false,
default: None,
unique: false,
suggestions: ColumnSuggestion::None {},
ignored_for: vec![],
secret: false,
},
module_settings::common_columns::created_at(),
]),
title_template: "Reason: {reason}",
operations: indexmap::indexmap! {
OperationType::View => OperationSpecific {
columns_to_set: indexmap::indexmap! {},
},
OperationType::Create => OperationSpecific {
columns_to_set: indexmap::indexmap! {
"created_at" => "{__now}",
},
},
OperationType::Delete => OperationSpecific {
columns_to_set: indexmap::indexmap! {},
}
},
validator: settings_wrap(NoOpValidator {}),
post_action: settings_wrap(NoOpPostAction {}),
title_template: "Reason: {reason}".to_string(),
supported_operations: vec![
OperationType::View,
OperationType::Save,
OperationType::Delete,
],
});

/// A custom data store is needed to handle the specific requirements of the lockdown module
Expand All @@ -196,7 +139,7 @@ pub struct LockdownDataStore {}
impl CreateDataStore for LockdownDataStore {
async fn create(
&self,
setting: &ConfigOption,
setting: &Setting,
guild_id: serenity::all::GuildId,
author: serenity::all::UserId,
data: &SettingsData,
Expand Down
4 changes: 0 additions & 4 deletions core/rust.bot_modules.moderation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,4 @@ impl silverpelt::module::Module for Module {
),
]
}

fn full_command_list(&self) -> Vec<silverpelt::module::CommandObj> {
modules_ext::create_full_command_list(self)
}
}
6 changes: 1 addition & 5 deletions core/rust.bot_modules.punishment_autotriggers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ impl silverpelt::module::Module for Module {
Some(Box::new(EventListener))
}

fn config_options(&self) -> Vec<module_settings::types::ConfigOption> {
fn config_options(&self) -> Vec<module_settings::types::Setting> {
vec![(*settings::AUTOTRIGGERS).clone()]
}

fn full_command_list(&self) -> Vec<silverpelt::module::CommandObj> {
modules_ext::create_full_command_list(self)
}
}

struct EventListener;
Expand Down
Loading

0 comments on commit c36715e

Please sign in to comment.