This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
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
3 changed files
with
145 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { CompoundCommandBuilder } from 'core'; | ||
import { feature as db } from 'db'; | ||
|
||
interface PermSchema { | ||
guild: string; | ||
name: string; | ||
group: string; | ||
} | ||
|
||
const builder = new CompoundCommandBuilder('perm', '権限の設定'); | ||
|
||
builder | ||
.subcommand('set', '値の更新') | ||
.addStringOption({ | ||
name: 'permission', | ||
description: '権限名', | ||
required: true, | ||
}) | ||
.addMentionableOption({ | ||
name: 'group', | ||
description: '対象のロールまたはユーザー', | ||
required: true, | ||
}) | ||
.build(async (interaction, permissionName, group) => { | ||
const connection = db.connection; | ||
const guild = interaction.guild; | ||
if (guild == null) { | ||
interaction.reply({ | ||
content: 'このコマンドはサーバー内で使用してください!', | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
const collection = connection.collection<PermSchema>('perms'); | ||
collection.insertOne({ | ||
guild: guild.id, | ||
name: permissionName, | ||
group: group.id, | ||
}); | ||
await interaction.reply( | ||
`権限を追加しました!\n権限名: ${permissionName}\nロール/メンバーID: ${group.id}`, | ||
); | ||
}); | ||
|
||
builder | ||
.subcommand('get', '値の取得') | ||
.addStringOption({ | ||
name: 'permission', | ||
description: '権限名', | ||
required: true, | ||
}) | ||
.build(async (interaction, permissionName) => { | ||
const connection = db.connection; | ||
const guild = interaction.guild; | ||
if (guild == null) { | ||
interaction.reply({ | ||
content: 'このコマンドはサーバー内で使用してください!', | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
const collection = connection.collection<PermSchema>('perms'); | ||
const result = await collection.findOne({ | ||
guild: guild.id, | ||
name: permissionName, | ||
}); | ||
if (result != null) { | ||
await interaction.reply( | ||
`権限名: ${permissionName}\nロール/メンバーID: ${result.group}`, | ||
); | ||
} else { | ||
await interaction.reply( | ||
`権限名: ${permissionName}\nその名前の権限はありません!`, | ||
); | ||
} | ||
}); | ||
|
||
export default builder.build(); |
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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import { Feature } from 'core'; | ||
import { CommandManager, Feature } from 'core'; | ||
import { Client } from 'discord.js'; | ||
import perm from './commands/perm'; | ||
import { feature as db } from 'db'; | ||
|
||
class PermsFeature extends Feature { | ||
enabled: boolean = true; | ||
|
||
name: string = 'perms'; | ||
|
||
dependencies: Feature[] = [db]; | ||
|
||
onLoad(client: Client<boolean>): void | PromiseLike<void> { | ||
CommandManager.default.addCommands([perm]); | ||
} | ||
} | ||
|
||
export const feature = new PermsFeature(); |