-
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.
- Loading branch information
Showing
7 changed files
with
240 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"tako": minor | ||
--- | ||
|
||
Added a /crosspost command that automatically publishes messages in an announcement channel. |
44 changes: 44 additions & 0 deletions
44
apps/docs/src/content/docs/en/commands/utility/crosspost.mdx
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,44 @@ | ||
--- | ||
title: Crosspost | ||
description: | | ||
A reference page for the '/crosspost' command inside the Tako Discord app. | ||
With '/crosspost', you can setup the app to automatically publish all messages in an announcement channel. | ||
--- | ||
|
||
import { Tabs, TabItem } from '@astrojs/starlight/components'; | ||
import Badge from '@astrojs/starlight/components/Badge.astro'; | ||
|
||
With `/crosspost`, you can setup the app to automatically publish all messages in an announcement channel. | ||
|
||
## Usage | ||
|
||
<Tabs> | ||
<TabItem label="Slash Commands"> | ||
`/crosspost [channel] [state]` | ||
|
||
**Example**: | ||
`/crosspost channel:#news state:true` will enable crossposting for the `#news` channel. | ||
</TabItem> | ||
</Tabs> | ||
|
||
## Permissions | ||
|
||
In order to use the `/crosspost` subcommands, you need the `Manage Channels` & `Manage Messages` permisions. | ||
:::tip | ||
You can change the permisions via `Server Settings > Integrations > Tako` in your Discord server. | ||
::: | ||
|
||
## Options | ||
|
||
<Tabs> | ||
<TabItem label="Channel"> | ||
<Badge text="Default: The channel you executed the command from" /> | ||
The channel to set the state of whether the app should automatically publish all new messages from or not. | ||
|
||
Needs to be an announcement channel! | ||
</TabItem> | ||
<TabItem label="State"> | ||
<Badge text="Default: The opposite of the current state, otherwise true" /> | ||
If set to `true`, the app will automatically publish all new messages from the channel. Otherwise, it will stop automatically publishing messages. | ||
</TabItem> | ||
</Tabs> |
2 changes: 2 additions & 0 deletions
2
apps/tako/prisma/migrations/20240519145728_crosspost/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Channel" ADD COLUMN "crosspost" BOOLEAN NOT NULL DEFAULT false; |
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,143 @@ | ||
import type { ChatInputCommandInteraction } from 'discord.js'; | ||
import { | ||
ChannelType, | ||
PermissionFlagsBits, | ||
SlashCommandBuilder, | ||
} from 'discord.js'; | ||
import config from '../../../config.ts'; | ||
import prisma from '../../database.ts'; | ||
import i18next from '../../i18n.ts'; | ||
import { | ||
createEmbed, | ||
getLanguage, | ||
slashCommandTranslator, | ||
} from '../../util/general.ts'; | ||
import type { Command } from '../index.ts'; | ||
|
||
export default { | ||
data: new SlashCommandBuilder() | ||
.setName(i18next.t('crosspost.name', { ns: 'utility' })) | ||
.setNameLocalizations(slashCommandTranslator('crosspost.name', 'utility')) | ||
.setDescription(i18next.t('crosspost.description', { ns: 'utility' })) | ||
.setDescriptionLocalizations( | ||
slashCommandTranslator('crosspost.description', 'utility'), | ||
) | ||
.addChannelOption((option) => | ||
option | ||
.setName(i18next.t('crosspost.options.channel.name', { ns: 'utility' })) | ||
.setNameLocalizations( | ||
slashCommandTranslator('crosspost.options.channel.name', 'utility'), | ||
) | ||
.setDescription( | ||
i18next.t('crosspost.options.channel.description', { ns: 'utility' }), | ||
) | ||
.setDescriptionLocalizations( | ||
slashCommandTranslator( | ||
'crosspost.options.channel.description', | ||
'utility', | ||
), | ||
) | ||
.addChannelTypes(ChannelType.GuildAnnouncement), | ||
) | ||
.addBooleanOption((option) => | ||
option | ||
.setName(i18next.t('crosspost.options.state.name', { ns: 'utility' })) | ||
.setNameLocalizations( | ||
slashCommandTranslator('crosspost.options.state.name', 'utility'), | ||
) | ||
.setDescription( | ||
i18next.t('crosspost.options.state.description', { ns: 'utility' }), | ||
) | ||
.setDescriptionLocalizations( | ||
slashCommandTranslator( | ||
'crosspost.options.state.description', | ||
'utility', | ||
), | ||
), | ||
) | ||
.setDefaultMemberPermissions( | ||
PermissionFlagsBits.ManageChannels | PermissionFlagsBits.ManageMessages, | ||
) | ||
.setDMPermission(false) | ||
.toJSON(), | ||
async execute(interaction: ChatInputCommandInteraction) { | ||
const channel = | ||
interaction.options.getChannel('channel') ?? interaction.channel; | ||
const existingData = await prisma.channel.findFirst({ | ||
where: { id: channel?.id }, | ||
select: { crosspost: true }, | ||
}); | ||
const state = | ||
interaction.options.getBoolean('state') ?? | ||
!existingData?.crosspost ?? | ||
true; | ||
const lng = await getLanguage( | ||
interaction.guildId, | ||
interaction.user.id, | ||
true, | ||
); | ||
|
||
if (channel?.type !== ChannelType.GuildAnnouncement) { | ||
await interaction.reply({ | ||
embeds: [ | ||
createEmbed({ | ||
color: config.colors.red, | ||
description: i18next.t( | ||
'crosspost.errors.invalidChannel.description', | ||
{ | ||
ns: 'utility', | ||
lng, | ||
}, | ||
), | ||
emoji: config.emojis.error, | ||
title: i18next.t('crosspost.errors.invalidChannel.title', { | ||
ns: 'utility', | ||
lng, | ||
}), | ||
}), | ||
], | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
|
||
await prisma.channel.upsert({ | ||
where: { id: channel.id }, | ||
create: { | ||
id: channel.id, | ||
crosspost: state, | ||
}, | ||
update: { | ||
crosspost: state, | ||
}, | ||
}); | ||
|
||
await interaction.reply({ | ||
embeds: [ | ||
createEmbed({ | ||
color: state ? config.colors.green : config.colors.red, | ||
description: i18next.t( | ||
'crosspost.success' + | ||
(state ? '.enabled' : '.disabled') + | ||
'.description', | ||
{ | ||
ns: 'utility', | ||
lng, | ||
channel: channel.id, | ||
}, | ||
), | ||
emoji: state ? config.emojis.success : config.emojis.error, | ||
title: i18next.t( | ||
'crosspost.success' + (state ? '.enabled' : '.disabled') + '.title', | ||
{ | ||
ns: 'utility', | ||
lng, | ||
channel: channel.id, | ||
}, | ||
), | ||
}), | ||
], | ||
ephemeral: true, | ||
}); | ||
}, | ||
} satisfies Command; |
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