-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add toggle for Japanese translation (#50)
* Add toggle for Japanese translation Fixes #49 - update package to 2.1.1 - add migration for translate Status, add entity - add command for toggleTranslate, translateStatus * Fix migration to be dynamic seeding of guild data Add toggle for Japanese translation Fixes #49
- Loading branch information
Showing
11 changed files
with
185 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { SlashCommandBuilder, PermissionFlagsBits, bold } from "discord.js"; | ||
import { CommandData } from "../utils/cmdLoader.js"; | ||
import { AppDataSource } from "../db/data-source.js"; | ||
import { GuildTranslate } from "../db/entity/GuildTranslate.js"; | ||
|
||
const guildTranslateRepo = AppDataSource.getRepository(GuildTranslate); | ||
|
||
const command = new SlashCommandBuilder() | ||
.setName("toggle-translate") | ||
.setDescription("Toggle auto-translation from Japanese to English for your server.") | ||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator); | ||
|
||
const toggleTranslate: CommandData = { | ||
command, | ||
autoComplete: () => {}, | ||
execute: async (interaction) => { | ||
// check if the user is an admin in the server | ||
if (!interaction.memberPermissions?.has(PermissionFlagsBits.Administrator)) { | ||
await interaction.editReply(`You need to be an admin to perform this action!`); | ||
return; | ||
} | ||
|
||
const guildId = interaction.guildId; | ||
// not a dm | ||
if (guildId) { | ||
const guildTranslate = await guildTranslateRepo.findOneByOrFail({ | ||
discordGuildId: guildId, | ||
}); | ||
guildTranslate.status = !guildTranslate.status; | ||
|
||
await guildTranslateRepo.upsert(guildTranslate, ["discordGuildId"]); | ||
|
||
await interaction.editReply( | ||
// need to convert from integer (0, 1) to bool to string | ||
`Set Japanese to English translation to ${bold(String(Boolean(guildTranslate.status)))}` | ||
); | ||
} | ||
}, | ||
}; | ||
|
||
export default toggleTranslate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { SlashCommandBuilder, PermissionFlagsBits, bold } from "discord.js"; | ||
import { CommandData } from "../utils/cmdLoader.js"; | ||
import { AppDataSource } from "../db/data-source.js"; | ||
import { GuildTranslate } from "../db/entity/GuildTranslate.js"; | ||
|
||
const guildTranslateRepo = AppDataSource.getRepository(GuildTranslate); | ||
|
||
const command = new SlashCommandBuilder() | ||
.setName("translate-status") | ||
.setDescription( | ||
"Check to see if Mittens is actively translating from Japanese to English for your server." | ||
) | ||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator); | ||
|
||
const translateStatus: CommandData = { | ||
command, | ||
autoComplete: () => {}, | ||
execute: async (interaction) => { | ||
// make sure that it's not a dm | ||
if (interaction.guildId) { | ||
// check if the user is an admin in the server | ||
if (!interaction.memberPermissions?.has(PermissionFlagsBits.Administrator)) { | ||
await interaction.editReply(`You need to be an admin to perform this action!`); | ||
return; | ||
} | ||
|
||
const guildTranslate = await guildTranslateRepo.findOneByOrFail({ | ||
discordGuildId: interaction.guildId, | ||
}); | ||
|
||
await interaction.editReply( | ||
// need to convert from integer (0, 1) to bool to string | ||
`Japanese to English translation is set to ${bold(String(Boolean(guildTranslate.status)))}` | ||
); | ||
} | ||
}, | ||
}; | ||
|
||
export default translateStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Entity, PrimaryGeneratedColumn, PrimaryColumn } from "typeorm"; | ||
|
||
@Entity({ name: "guild_translate_statuses" }) | ||
export class GuildTranslate { | ||
constructor() {} | ||
|
||
// the name of the group | ||
@PrimaryColumn({ type: "text", name: "discord_guild_id" }) | ||
discordGuildId: string; | ||
|
||
@PrimaryColumn({ type: "integer", name: "status" }) | ||
status: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { MigrationInterface, QueryRunner, Table } from "typeorm"; | ||
import { client } from "../../bot.js"; | ||
|
||
export class AddTranslateStatuses1688860131193 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.createTable( | ||
new Table({ | ||
name: "guild_translate_statuses", | ||
columns: [ | ||
{ | ||
name: "discord_guild_id", | ||
type: "text", | ||
isPrimary: true, | ||
}, | ||
{ | ||
name: "status", | ||
type: "integer", // bool is integer (0, 1) | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
// insert curr servers | ||
const guildsInsertStmt = `INSERT INTO guild_translate_statuses (discord_guild_id, status) VALUES (?, ?)`; | ||
const guilds = await client.guilds.fetch(); | ||
guilds.forEach(async (server) => { | ||
await queryRunner.query(guildsInsertStmt, [server.id, false]); | ||
}); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropTable("guild_translate_statuses"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters