Remove premium features

This commit is contained in:
Lukas | AstroGD 2022-11-29 01:56:51 +01:00
parent 361326c31e
commit ee9039c239
Signed by: AstroGD
GPG Key ID: 82A5E6C236C535AA
8 changed files with 12 additions and 69 deletions

View File

@ -1,5 +1,4 @@
import { getGuildSetting, isPremiumActive } from "../tools/data";
import moment from "moment";
import { getGuildSetting } from "../tools/data";
import { Badword, database, GuildSetting } from "../data";
import { Console } from "console";
@ -13,7 +12,6 @@ export default async function execute(args: string[]) {
case "info": {
if (!args[1]) return printHelp();
const settings = await getGuildSetting(args[1]);
const isPremium = isPremiumActive(settings.isPremiumUntil);
const wordCount = await database.getRepository(Badword).count({
where: {
guildID: args[1]
@ -21,36 +19,12 @@ export default async function execute(args: string[]) {
});
console.log(`Guild ${args[1]}:
- Premium: ${isPremium ? `ACTIVE for ${moment(settings.isPremiumUntil).fromNow(true)}` : "INACTIVE"}
- Preserve Settings: ${settings.preserveDataOnGuildLeave ? "ENABLED" : "DISABLED"}
- Logchannel: ${settings.notificationChannelID ? `ENABLED (${settings.notificationChannelID})` : "DISABLED"}
- blocked Words: ${wordCount}`);
break;
}
case "setpremium": {
if (!args[1] || !args[2]) return printHelp();
const settings = await getGuildSetting(args[1]);
if (args[2].toLowerCase() === "null") {
settings.isPremiumUntil = null;
await database.getRepository(GuildSetting).save(settings);
console.log("Premium status removed for guild " + args[1]);
break;
}
const date = new Date(args[2]);
if (isNaN(Number(date))) return printHelp();
const now = new Date();
if (now > date) return console.log("Date lies in the past");
settings.isPremiumUntil = date;
await database.getRepository(GuildSetting).save(settings);
console.log(`Premium status for guild ${args[1]} is now active for ${moment(date).fromNow(true)}`);
break;
}
case "words": {
if (!args[1] || !args[2]) return printWordHelp();
@ -152,7 +126,6 @@ function printHelp() {
console.log(`Usage "guild":
guild info [GUILDID]
guild setPremium [GUILDID] [YYYY-MM-DD or NULL]
guild words [get|add|remove|clear]
guild delete [GUILDID]`);
}

View File

@ -1,7 +1,7 @@
import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
import { database, Badword } from "../data";
import { IsNull } from "typeorm";
import { getGuildSetting, isPremiumActive } from "../tools/data";
import { getGuildSetting } from "../tools/data";
import getDefaultEmbed, { getFailedEmbed, getSuccessEmbed } from "../tools/defaultEmbeds";
import { getGuildChannel } from "../tools/discord";
import { Color, Emoji } from "../tools/design";
@ -46,7 +46,6 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
if (!interaction.guildId) throw new Error("Command was executed in DM context");
const settings = await getGuildSetting(interaction.guildId);
const isPremium = isPremiumActive(settings.isPremiumUntil);
const logChannel = settings.notificationChannelID ? await getGuildChannel(interaction.guildId, settings.notificationChannelID) : null;
@ -63,7 +62,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
}
});
const limit = isPremium ? 100 : 10;
const limit = 100;
if (count >= limit) {
const embed = getFailedEmbed();
embed.setDescription(`You reached the word limit for your guild. Please delete a word before adding a new one`);

View File

@ -1,7 +1,6 @@
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
import { IsNull } from "typeorm";
import { Badword, database } from "../data";
import { getGuildSetting, isPremiumActive } from "../tools/data";
import getDefaultEmbed from "../tools/defaultEmbeds";
import pack from "../../package.json";
import { Color, Emoji } from "../tools/design";
@ -14,8 +13,6 @@ builder.setDMPermission(false);
async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
if (!interaction.inGuild()) throw new Error("Command was executed outside guild context");
const settings = await getGuildSetting(interaction.guildId);
const isPremium = isPremiumActive(settings.isPremiumUntil);
const globalBlockedWordsCount = await database.getRepository(Badword).count({
where: {
guildID: IsNull()
@ -30,17 +27,13 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
const embed = getDefaultEmbed();
embed.setTitle(`${Emoji.SECURITY_CHALLENGE} Channel filter V${pack.version} by AstroGD®`);
embed.setDescription(`Codename eu.astrogd.white-leopard`);
embed.setColor(isPremium ? Color.PREMIUM_ORANGE : Color.INFORMING_BLUE);
embed.setColor(Color.INFORMING_BLUE);
embed.addFields({
name: "What does this bot do?",
value: "This bot checks for blocked words contained in channel names and reverts the changes if found."
},{
name: "Author",
value: `This bot was created by AstroGD#0001 ${Emoji.ASTROGD} mainly for the official r/Overwatch2 Subreddit Discord server`
},{
name: "Server status",
value: `${isPremium ? Emoji.PREMIUM : Emoji.SWITCH_OFF} Premium features are ${isPremium ? "enabled" : "disabled"} on this server`,
inline: true
},{
name: "Global word count",
value: globalBlockedWordsCount.toString(),

View File

@ -1,8 +1,7 @@
import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
import { Badword, database } from "../data";
import { getGuildSetting, isPremiumActive } from "../tools/data";
import { getGuildSetting } from "../tools/data";
import getDefaultEmbed from "../tools/defaultEmbeds";
import moment from "moment";
import { Color, Emoji } from "../tools/design";
import { getGuildChannel, getChannelPermission } from "../tools/discord";
@ -16,7 +15,6 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
if (!interaction.inGuild()) throw new Error("Interaction was performed outside guild context");
const settings = await getGuildSetting(interaction.guildId);
const isPremium = await isPremiumActive(settings.isPremiumUntil);
const wordCount = await database.getRepository(Badword).count({
where: {
guildID: interaction.guildId
@ -27,19 +25,15 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
const embed = getDefaultEmbed();
embed.setTitle(`Settings from guild ${interaction.guild?.name || ""} (${interaction.guildId})`);
embed.setDescription(isPremium ? `${Emoji.PREMIUM} your subscription ends in ${moment(settings.isPremiumUntil).fromNow(true)}` : `Consider Premium status to get an increased blocklist`);
embed.setColor(isPremium ? Color.PREMIUM_ORANGE : Color.INFORMING_BLUE);
embed.setDescription("Thanks for using this bot");
embed.setColor(Color.INFORMING_BLUE);
embed.addFields({
name: "Premium",
value: isPremium ? `${Emoji.PREMIUM} active` : `${Emoji.SWITCH_OFF} inactive`,
inline: true
}, {
name: "Logchannel",
value: settings.notificationChannelID ? `<#${settings.notificationChannelID}>` : "Not configured",
inline: true
}, {
name: "Words in Blocklist",
value: `${wordCount}/${isPremium ? "100" : "10"}`,
value: `${wordCount}/100`,
inline: true
}, {
name: `Preserve data on server leave is ${settings.preserveDataOnGuildLeave ? "active" : "inactive"}`,

View File

@ -1,7 +1,7 @@
import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
import { IsNull } from "typeorm";
import { Badword, database } from "../data";
import { getGuildSetting, isPremiumActive } from "../tools/data";
import { getGuildSetting } from "../tools/data";
const builder = new SlashCommandBuilder();
builder.setName("showblocklist");
@ -11,9 +11,6 @@ builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels);
async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
if (!interaction.inGuild()) throw new Error("Command was executed outside guild context");
const settings = await getGuildSetting(interaction.guildId);
const isPremium = isPremiumActive(settings.isPremiumUntil);
const guildBadWords = await database.getRepository(Badword).find({
select: {
@ -30,7 +27,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
});
interaction.reply({
content: `\`\`\`Global bad word list\`\`\`\n||${globalBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||\n\`\`\`Local server bad word list (${guildBadWords.length}/${isPremium ? 100 : 10})\`\`\`\n||${guildBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||`,
content: `\`\`\`Global bad word list\`\`\`\n||${globalBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||\n\`\`\`Local server bad word list (${guildBadWords.length}/100)\`\`\`\n||${guildBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||`,
ephemeral: true
}).catch(() => {});
}

View File

@ -8,9 +8,6 @@ export class GuildSetting {
@Column("varchar", { nullable: true, default: null })
notificationChannelID!: string | null;
@Column("timestamp", { nullable: true, default: null })
isPremiumUntil!: Date | null;
@Column("boolean", { default: false })
preserveDataOnGuildLeave!: boolean
}

View File

@ -1,6 +1,6 @@
import client from "../client";
import { Events } from "discord.js";
import { getGuildSetting, isPremiumActive } from "../tools/data";
import { getGuildSetting } from "../tools/data";
import { Badword, database } from "../data";
import { IsNull } from "typeorm";
import getDefaultEmbed, { getFailedEmbed } from "../tools/defaultEmbeds";
@ -14,7 +14,6 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
const guild = oldChannel.guild;
const settings = await getGuildSetting(guild.id);
const isPremium = isPremiumActive(settings.isPremiumUntil);
const globalBlocklist = await database.getRepository(Badword).find({
where: {
@ -69,7 +68,7 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`);
embed.setDescription(`<#${newChannel.id}> (${newChannel.id}) has been renamed because its name contained a blocked word.`);
embed.setColor(Color.WARNING_YELLOW);
if (isPremium) embed.addFields({
embed.addFields({
name: "Detected banned word:",
value: `||${found}||`,
inline: true

View File

@ -10,18 +10,9 @@ export async function getGuildSetting(guildID: string): Promise<GuildSetting> {
if (!guildSetting) {
guildSetting = new GuildSetting();
guildSetting.id = guildID;
guildSetting.isPremiumUntil = null;
guildSetting.notificationChannelID = null;
guildSetting.preserveDataOnGuildLeave = false;
}
return guildSetting;
}
export function isPremiumActive(timestamp: Date | null): boolean {
if (timestamp === null) return false;
const now = Number(new Date());
const activeUntil = Number(timestamp);
return now < activeUntil;
}