Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit 4b5abce2c6dc9da08f303eac1985d9634a45666f
parent 93875be258e2260909f376459a3c520b9f4b0069
Author: Demonstrandum <moi@knutsen.co>
Date:   Mon, 23 Mar 2020 17:40:53 +0000

Merge branch 'master' of github.com:Demonstrandum/Simp-O-Matic

Diffstat:
Mlib/default.ts | 2+-
Mlib/extensions.ts | 98++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mlib/main.ts | 3+--
Mlib/utils.ts | 4++--
4 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/lib/default.ts b/lib/default.ts @@ -2,7 +2,7 @@ /// and to act as a reference to how the config shall be /// laid out. All fields are accounted for here. -const DEFAULT_GUILD_CONFIG : ConfigType = { +const DEFAULT_GUILD_CONFIG : Types.Config = { main_channel: null, system_channel: null, pp_sizes: { diff --git a/lib/extensions.ts b/lib/extensions.ts @@ -5,60 +5,62 @@ declare global { HELP_SOURCE: string, HELP_KEY: string, GIT_URL: string, HELP_MESSAGES: string[], HELP_SECTIONS: string[] , ALL_HELP: string[], - CONFIG: ConfigType, SECRETS: any, KNOWN_COMMANDS: string[], + CONFIG: Types.Config, SECRETS: any, KNOWN_COMMANDS: string[], expand_alias: (operator: string, args: string[], message: Message) => string }; - type MatchType = { - match: string | RegExp, - response: string - }; - - type IgnoreType = { - commands?: boolean, - commands_elevated?: boolean, - speech?: boolean - }; - - type ConfigType = { - main_channel: string, - system_channel: string, - pp_sizes: { [key: string]: number } - weather_locations: { [key: string]: string }, - commands: { - prefix: string, - max_history: number, - not_understood: string, - aliases: { [key: string]: string }, - } - rules: { - respond: MatchType[], - reject: MatchType[], - replace: MatchType[], - trigger: MatchType[], - blacklist: { - channels: string[], - users: { - [key: string]: IgnoreType + namespace Types { + export type Match = { + match: string | RegExp, + response: string + }; + + export type Ignore = { + commands?: boolean, + commands_elevated?: boolean, + speech?: boolean + }; + + type Config = { + main_channel: string, + system_channel: string, + pp_sizes: { [key: string]: number } + weather_locations: { [key: string]: string }, + commands: { + prefix: string, + max_history: number, + not_understood: string, + aliases: { [key: string]: string }, + } + rules: { + respond: Match[], + reject: Match[], + replace: Match[], + trigger: Match[], + blacklist: { + channels: string[], + users: { + [key: string]: Ignore + }, + groups: { + [key: string]: Ignore + } }, - groups: { - [key: string]: IgnoreType + whitelist: { + users: string[], + groups: string[] } - }, - whitelist: { - users: string[], - groups: string[] } - } - }; - - type GlobalConfigType = { - name: string, - tag: string, - permissions: number, - lang: 'en' | 'en-us' | 'en-gb', - guilds: { [key: string]: ConfigType } - }; + }; + + type GlobalConfig = { + name: string, + tag: string, + permissions: number, + lang: 'en' | 'en-us' | 'en-gb', + guilds: { [key: string]: Config } + }; + } interface Array<T> { head(): T; diff --git a/lib/main.ts b/lib/main.ts @@ -30,7 +30,7 @@ import { Guild } from 'discord.js'; // Anything that hasn't been defined in `bot.json` // will be taken care of by the defaults. -let GLOBAL_CONFIG : GlobalConfigType = { +let GLOBAL_CONFIG : Types.GlobalConfig = { name: "Simp'O'Matic", tag: "#1634", permissions: 8, @@ -529,4 +529,3 @@ pastebin_latest().then(res => { // Start The Simp'O'Matic. CLIENT = SimpOMatic.start(); }).catch(console.warn); - diff --git a/lib/utils.ts b/lib/utils.ts @@ -106,8 +106,8 @@ export const recursive_regex_to_string = o => { return o; }; -export const export_config = (obj: GlobalConfigType, { ugly = false }) => { - const o: GlobalConfigType = recursive_regex_to_string(deep_clone(obj)); +export const export_config = (obj: Types.GlobalConfig, { ugly = false }) => { + const o: Types.GlobalConfig = recursive_regex_to_string(deep_clone(obj)); // Make sure all rules are unique, // i.e. eliminate duplicate rules.