Skip to content

Commit

Permalink
Merge commit '29ce888cc25fd9b3eea82504c2b0ab3d8453fa2d'
Browse files Browse the repository at this point in the history
  • Loading branch information
a179346 committed Aug 9, 2021
2 parents a7d1931 + 29ce888 commit 6c4ae32
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 216 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
2 changes: 1 addition & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14.17.0-alpine
FROM node:16.6.1-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
Expand Down
324 changes: 157 additions & 167 deletions server/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"axios": "^0.21.1",
"cron": "^1.8.2",
"discord.js": "^13.0.0-dev.fe6cc0c.1625184228",
"discord.js": "^13.0.1",
"dotenv": "^10.0.0",
"mysql": "^2.18.1",
"reflect-metadata": "^0.1.13",
Expand All @@ -43,5 +43,5 @@
"ts-node": "^10.1.0",
"typescript": "^4.2.4"
},
"nodeVersion": "14.15.4"
"nodeVersion": "16.6.1"
}
4 changes: 2 additions & 2 deletions server/src/Class/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Bot {
// console.log(commands);
if (commands.size < this.commandSet.size) {
try {
for (const command of this.commandSet.array()) {
for (const command of this.commandSet.values()) {
await this.client.application.commands.create(command.options);
}
} catch (error) {
Expand All @@ -45,7 +45,7 @@ class Bot {
});


this.client.on('interaction', async (interaction) => {
this.client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand())
return;
try {
Expand Down
6 changes: 3 additions & 3 deletions server/src/Class/Command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApplicationCommandData, Collection, CommandInteraction, CommandInteractionOption } from 'discord.js';
import { ApplicationCommandData, CommandInteraction, CommandInteractionOptionResolver } from 'discord.js';

type RunEvent = (interaction: CommandInteraction, options: Collection<string, CommandInteractionOption>) => Promise<void>;
type RunEvent = (interaction: CommandInteraction, options: CommandInteractionOptionResolver) => Promise<void>;

export class Command {
public readonly options: ApplicationCommandData;
Expand All @@ -12,7 +12,7 @@ export class Command {
this.runEvent = runEvent;
}

public async run (interaction: CommandInteraction, options: Collection<string, CommandInteractionOption>) {
public async run (interaction: CommandInteraction, options: CommandInteractionOptionResolver) {
await this.runEvent(interaction, options);
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/Class/CommandSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command } from './Command';

export class CommandSet extends Collection<string, Command> {
async init (): Promise<void> {
for (const command of this.array()) {
for (const command of this.values()) {
await command.init();
}
}
Expand Down
10 changes: 5 additions & 5 deletions server/src/Class/NestedCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Subcommand } from './Subcommand';
import { ReplyError } from './ReplyError';
import { CommandOptionType } from '../interface/CommandOptionType';
import { Command } from './Command';
import { ApplicationCommandData, Collection, CommandInteraction, CommandInteractionOption } from 'discord.js';
import { ApplicationCommandData, CommandInteraction, CommandInteractionOptionResolver } from 'discord.js';

type CheckEvent = (interaction: CommandInteraction, options: Collection<string, CommandInteractionOption>) => Promise<void>;
type CheckEvent = (interaction: CommandInteraction, options: CommandInteractionOptionResolver) => Promise<void>;

export class NestedCommand extends Command {
private readonly subcommandMap: Map<string, Subcommand> = new Map();
Expand All @@ -29,8 +29,8 @@ export class NestedCommand extends Command {
this.subcommandMap.set(subcommand.options.name, subcommand);
}

private async nestedRun (interaction: CommandInteraction, options: Collection<string, CommandInteractionOption>) {
const commamdOptions = options.first();
private async nestedRun (interaction: CommandInteraction, options: CommandInteractionOptionResolver) {
const commamdOptions = options.data[0];
if (!commamdOptions || !commamdOptions.options || commamdOptions.type !== CommandOptionType.SUB_COMMAND)
throw new ReplyError('Invalid command: ' + interaction.commandName);

Expand All @@ -43,6 +43,6 @@ export class NestedCommand extends Command {

if (this.checkEvent)
await this.checkEvent(interaction, options);
await subcommand.run(interaction, commamdOptions.options);
await subcommand.run(interaction, options);
}
}
6 changes: 3 additions & 3 deletions server/src/Class/Subcommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandInteraction, ApplicationCommandOption, Collection, CommandInteractionOption } from 'discord.js';
import { CommandInteraction, ApplicationCommandOption, CommandInteractionOptionResolver } from 'discord.js';

type SubcommandEvent = (interaction: CommandInteraction, options: Collection<string, CommandInteractionOption>) => Promise<void>;
type SubcommandEvent = (interaction: CommandInteraction, options: CommandInteractionOptionResolver) => Promise<void>;

export class Subcommand {
public readonly options: ApplicationCommandOption;
Expand All @@ -11,7 +11,7 @@ export class Subcommand {
this.subcommandEvent = subcommandEvent;
}

public async run (interaction: CommandInteraction, options: Collection<string, CommandInteractionOption>): Promise<void> {
public async run (interaction: CommandInteraction, options: CommandInteractionOptionResolver): Promise<void> {
await this.subcommandEvent(interaction, options);
}
}
4 changes: 2 additions & 2 deletions server/src/Command/Channel/ChannelGetSubcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const ChannelGetSubcommand = new Subcommand({
required: true,
}, ]
}, async (interaction, options) => {
const name = options.get('name')?.value;
const privateReply = options.get('private-reply')?.value;
const name = options.getString('name');
const privateReply = options.getBoolean('private-reply');
if (typeof name !== 'string')
throw new ReplyError('Invalid Options: "name"');
if (typeof privateReply !== 'boolean')
Expand Down
4 changes: 2 additions & 2 deletions server/src/Command/Live/LiveGetSubcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const LiveGetSubcommand = new Subcommand({
required: true,
}, ]
}, async (interaction, options) => {
const name = options.get('name')?.value;
const privateReply = options.get('private-reply')?.value;
const name = options.getString('name');
const privateReply = options.getBoolean('private-reply');
if (typeof name !== 'string')
throw new ReplyError('Invalid Options: "name"');
if (typeof privateReply !== 'boolean')
Expand Down
6 changes: 3 additions & 3 deletions server/src/Command/Live/LiveListSubcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const LiveListSubcommand = new Subcommand({
required: true,
}, ]
}, async (interaction, options) => {
const privateReply = options.get('private-reply')?.value;
const onlyLive = options.get('only-live')?.value;
const privateReply = options.getBoolean('private-reply');
const onlyLive = options.getBoolean('only-live');
if (typeof privateReply !== 'boolean')
throw new ReplyError('Invalid Options: "private-reply"');
if (typeof onlyLive !== 'boolean')
throw new ReplyError('Invalid Options: "only-live"');

const subscriptions = await SubscriptionDao.list(interaction.channelID);
const subscriptions = await SubscriptionDao.list(interaction.channelId);
if (subscriptions.length === 0)
throw new ReplyError('No channel subscribed.');

Expand Down
12 changes: 6 additions & 6 deletions server/src/Command/Permission/PermissionAddSubcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ const PermissionAddSubcommand = new Subcommand({
required: true,
}, ]
}, async (interaction, options) => {
const permissionType = options.get('permission-type')?.value as PermissionType;
const role = options.get('role')?.value;
const permissionType = options.getString('permission-type') as PermissionType;
const role = options.getRole('role');
if (!(Object.values(PermissionType).includes(permissionType)))
throw new ReplyError('Invalid Options: "permission-type"');
if (typeof role !== 'string')
if (!role)
throw new ReplyError('Invalid Options: "role"');
const roleId = Lib.ToSnowflake(role);
const roleId = Lib.ToSnowflake(role.id);

const roleName = interaction.guild?.roles.cache.get(roleId)?.name;
if (!roleName)
throw new ReplyError('Unknown Role Id: "' + role + '". Please retry later.');
throw new ReplyError('Unknown Role Id: "' + role.id + '". Please retry later.');

await PermissionDao.insert(interaction.channelID, permissionType, roleId);
await PermissionDao.insert(interaction.channelId, permissionType, roleId);

interaction.reply({
content: 'Permission added: "' + roleName + '" for "' + permissionType + '"',
Expand Down
6 changes: 3 additions & 3 deletions server/src/Command/Permission/PermissionGetSubcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const PermissionGetSubcommand = new Subcommand({
required: true,
}, ]
}, async (interaction, options) => {
const permissionType = options.get('permission-type')?.value as PermissionType;
const privateReply = options.get('private-reply')?.value;
const permissionType = options.getString('permission-type') as PermissionType;
const privateReply = options.getBoolean('private-reply');
if (!(Object.values(PermissionType).includes(permissionType)))
throw new ReplyError('Invalid Options: "permission-type"');
if (typeof privateReply !== 'boolean')
throw new ReplyError('Invalid Options: "private-reply"');

const permissions = await PermissionDao.list(interaction.channelID, permissionType);
const permissions = await PermissionDao.list(interaction.channelId, permissionType);

const prefix = '\n:ballot_box_with_check: ';
let info = '【Permission for "' + permissionType + '"】';
Expand Down
12 changes: 6 additions & 6 deletions server/src/Command/Permission/PermissionRemoveSubcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ const PermissionRemoveSubcommand = new Subcommand({
required: true,
}, ]
}, async (interaction, options) => {
const permissionType = options.get('permission-type')?.value as PermissionType;
const role = options.get('role')?.value;
const permissionType = options.getString('permission-type') as PermissionType;
const role = options.getRole('role');
if (!(Object.values(PermissionType).includes(permissionType)))
throw new ReplyError('Invalid Options: "permission-type"');
if (typeof role !== 'string')
if (!role)
throw new ReplyError('Invalid Options: "role"');
const roleId = Lib.ToSnowflake(role);
const roleId = Lib.ToSnowflake(role.id);

const roleName = interaction.guild?.roles.cache.get(roleId)?.name;
if (!roleName)
throw new ReplyError('Unknown Role Id: "' + role + '". Please retry later.');
throw new ReplyError('Unknown Role Id: "' + role.id + '". Please retry later.');

await PermissionDao.remove(interaction.channelID, permissionType, roleId);
await PermissionDao.remove(interaction.channelId, permissionType, roleId);

interaction.reply({
content: 'Permission removed: "' + roleName + '" for "' + permissionType + '"',
Expand Down
4 changes: 2 additions & 2 deletions server/src/Command/Subscription/SubAddSubcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const SubAddSubcommand = new Subcommand({
required: true,
} ]
}, async (interaction, options) => {
const name = options.get('name')?.value;
const name = options.getString('name');
if (typeof name !== 'string')
throw new ReplyError('Invalid Options: "name"');

const channelNicknameVal = await ChannelNicknameDao.get(name);
if (!channelNicknameVal)
throw new ReplyError('Holomem not found: ' + name);

await SubscriptionDao.insert(interaction.channelID, channelNicknameVal.channel.id);
await SubscriptionDao.insert(interaction.channelId, channelNicknameVal.channel.id);

interaction.reply({
content: 'Subscription added: 【' + channelNicknameVal.channel.name + '】',
Expand Down
4 changes: 2 additions & 2 deletions server/src/Command/Subscription/SubListSubcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const SubListSubcommand = new Subcommand({
required: true,
}, ],
}, async (interaction, options) => {
const privateReply = options.get('private-reply')?.value;
const privateReply = options.getBoolean('private-reply');
if (typeof privateReply !== 'boolean')
throw new ReplyError('Invalid Options: "private-reply"');

const list = await SubscriptionDao.list(interaction.channelID);
const list = await SubscriptionDao.list(interaction.channelId);

let info = '【Subscription List】';
if (list.length === 0)
Expand Down
4 changes: 2 additions & 2 deletions server/src/Command/Subscription/SubRemoveSubcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const SubRemoveSubcommand = new Subcommand({
required: true,
} ]
}, async (interaction, options) => {
const name = options.get('name')?.value;
const name = options.getString('name');
if (typeof name !== 'string')
throw new ReplyError('Invalid Options: "name"');

const channelNicknameVal = await ChannelNicknameDao.get(name);
if (!channelNicknameVal)
throw new ReplyError('Holomem not found: ' + name);

await SubscriptionDao.remove(interaction.channelID, channelNicknameVal.channel.id);
await SubscriptionDao.remove(interaction.channelId, channelNicknameVal.channel.id);

interaction.reply({
content: 'Subscription removed: 【' + channelNicknameVal.channel.name + '】',
Expand Down
4 changes: 2 additions & 2 deletions server/src/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function enumToChoices (enumVal: {[key: string]: any}): ApplicationCommandOption

async function checkPermission (interaction: CommandInteraction, permissionType: PermissionType, ownerDefaultEnable: boolean): Promise<boolean> {
// channel owner
if (ownerDefaultEnable && interaction.guild?.ownerID === interaction.user.id)
if (ownerDefaultEnable && interaction.guild?.ownerId === interaction.user.id)
return true;

// DM
Expand All @@ -68,7 +68,7 @@ async function checkPermission (interaction: CommandInteraction, permissionType:
if (!interaction.member || !(interaction.member instanceof GuildMember))
return false;

const permissions = await PermissionDao.list(interaction.channelID, permissionType);
const permissions = await PermissionDao.list(interaction.channelId, permissionType);
const member = await interaction.member.fetch(true);
for (const permission of permissions) {
if (member.roles.cache.has(permission.role_id))
Expand Down

0 comments on commit 6c4ae32

Please sign in to comment.