Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

いろいろ #28

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 120,
"printWidth": 150,
"plugins": ["@trivago/prettier-plugin-sort-imports"]
}
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"license": "MIT",
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/node-cron": "^3.0.11",
"@types/node-os-utils": "^1.3.4",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
Expand All @@ -28,6 +29,7 @@
"discord.js": "^14.12.1",
"dotenv": "^16.3.2",
"fs": "^0.0.1-security",
"node-cron": "^3.0.3",
"node-os-utils": "^1.3.7",
"os": "^0.1.2"
}
Expand Down
5 changes: 1 addition & 4 deletions src/Events/onGuildRoleCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export async function onGuildRoleCreate(role: Role) {
const channel = role.guild.channels.cache.get(serverData.channelId);
if (channel && channel.isTextBased()) {
if (!role.guild?.members.me?.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages)) return;
const embed = new EmbedBuilder()
.setDescription(`新しいロール ${role} が作成されました`)
.setTimestamp()
.setColor('#0099ff');
const embed = new EmbedBuilder().setDescription(`新しいロール ${role} が作成されました`).setTimestamp().setColor('#0099ff');
channel.send({ embeds: [embed] });
}
} catch (error) {
Expand Down
5 changes: 1 addition & 4 deletions src/Events/onGuildRoleDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export async function onGuildRoleDelete(role: Role) {
const channel = role.guild.channels.cache.get(serverData.channelId);
if (channel && channel.isTextBased()) {
if (!role.guild.members.me?.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages)) return;
const embed = new EmbedBuilder()
.setDescription(`${role.name} ロールが削除されました`)
.setTimestamp()
.setColor('#0099ff');
const embed = new EmbedBuilder().setDescription(`${role.name} ロールが削除されました`).setTimestamp().setColor('#0099ff');
channel.send({ embeds: [embed] });
}
} catch (error) {
Expand Down
5 changes: 1 addition & 4 deletions src/Events/onGuildRoleUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export async function onGuildRoleUpdate(oldRole: Role, newRole: Role) {
const serverData = data[serverId];
if (!serverData) return;
try {
const embed = new EmbedBuilder()
.setTitle('ロールが更新されました')
.setDescription(`${newRole}`)
.setColor('#0099ff');
const embed = new EmbedBuilder().setTitle('ロールが更新されました').setDescription(`${newRole}`).setColor('#0099ff');
const changes = [];
if (oldRole.name !== newRole.name) {
changes.push(`ロール名: ${oldRole.name} → ${newRole.name}`);
Expand Down
4 changes: 1 addition & 3 deletions src/Events/onMessageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export async function onMessageCreate(message: Message): Promise<Awaitable<void>
if (
message.author.bot ||
message.guild?.members.me?.communicationDisabledUntil !== null ||
!message.guild.members.me
.permissionsIn(message.channel as GuildTextBasedChannel)
.has(PermissionsBitField.Flags.SendMessages) ||
!message.guild.members.me.permissionsIn(message.channel as GuildTextBasedChannel).has(PermissionsBitField.Flags.SendMessages) ||
bannedServers.includes(message.guild.id)
)
return;
Expand Down
4 changes: 1 addition & 3 deletions src/Events/onMessageDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export async function onMessageDelete(message: Message | PartialMessage) {
if (bannedUsers.includes((message.author as User).id) || bannedServers.includes((message.guild as Guild).id)) return;
if (
!message.content ||
!message.guild?.members.me
?.permissionsIn(message.channel as GuildBasedChannel)
.has(PermissionsBitField.Flags.SendMessages) ||
!message.guild?.members.me?.permissionsIn(message.channel as GuildBasedChannel).has(PermissionsBitField.Flags.SendMessages) ||
!message.guild
)
return;
Expand Down
12 changes: 3 additions & 9 deletions src/Events/onMessageUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { EmbedBuilder, Guild, Message, PartialMessage, PermissionsBitField, User
import { readFileSync } from 'fs';

export const onMessageUpdate = async (oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage) => {
if (bannedUsers.includes((newMessage.author as User).id) || bannedServers.includes((newMessage.guild as Guild).id))
return;
if (bannedUsers.includes((newMessage.author as User).id) || bannedServers.includes((newMessage.guild as Guild).id)) return;
if ((oldMessage.author as User).bot || oldMessage.content === newMessage.content || !oldMessage.guild) return;
const serverId = oldMessage.guild.id;
const rawData = readFileSync('./database/msglogs.json', 'utf-8');
Expand All @@ -17,13 +16,8 @@ export const onMessageUpdate = async (oldMessage: Message | PartialMessage, newM
if (channel && channel.isTextBased()) {
if (!oldMessage.guild?.members.me?.permissionsIn(channel).has(PermissionsBitField.Flags.SendMessages)) return;
const embed = new EmbedBuilder()
.setDescription(
`${oldMessage.channel}で${oldMessage.author}がメッセージを編集しました。\n [メッセージへジャンプ](${newMessage.url})`
)
.addFields(
{ name: '変更前', value: oldMessage.content ?? 'なし' },
{ name: '変更後', value: newMessage.content ?? 'なし' }
)
.setDescription(`${oldMessage.channel}で${oldMessage.author}がメッセージを編集しました。\n [メッセージへジャンプ](${newMessage.url})`)
.addFields({ name: '変更前', value: oldMessage.content ?? 'なし' }, { name: '変更後', value: newMessage.content ?? 'なし' })
.setColor('#0099ff')
.setThumbnail((oldMessage.author as User).displayAvatarURL())
.setTimestamp();
Expand Down
6 changes: 1 addition & 5 deletions src/Events/onReady.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ export function onReady(client: Client) {
'Discord.js': version,
'Node.js': process.version,
Plattform: process.platform + ' | ' + process.arch,
Memory:
(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) +
'MB | ' +
(process.memoryUsage().rss / 1024 / 1024).toFixed(2) +
'MB'
Memory: (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) + 'MB | ' + (process.memoryUsage().rss / 1024 / 1024).toFixed(2) + 'MB'
// Quote from: https://github.com/Nich87/Faith
});
}
6 changes: 2 additions & 4 deletions src/commands/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { embeds } from '../embeds';
import { Message, PermissionsBitField } from 'discord.js';

export async function banCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.BanMembers))
return message.reply(embeds.PermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers))
return message.reply(embeds.banPermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.BanMembers)) return message.reply(embeds.PermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) return message.reply(embeds.banPermissionError);
const member = message.mentions.members?.first();
if (!member) return message.reply(embeds.banHelp);
member
Expand Down
3 changes: 1 addition & 2 deletions src/commands/banlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { embeds } from '../embeds';
import { Message, PermissionsBitField, EmbedBuilder } from 'discord.js';

export async function banlistCommand(message: Message) {
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers))
return message.reply(embeds.banlistPermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.BanMembers)) return message.reply(embeds.banlistPermissionError);
await message.guild.bans
.fetch()
.then((bans) => {
Expand Down
10 changes: 3 additions & 7 deletions src/commands/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { embeds } from '../embeds';
import { ChannelType, Message, PermissionsBitField } from 'discord.js';

export async function clearCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages))
return message.reply(embeds.PermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageMessages))
return message.reply(embeds.clearPermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages)) return message.reply(embeds.PermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageMessages)) return message.reply(embeds.clearPermissionError);
const member = message.mentions.users.first();
const amountString = message.content.split(' ')[2];
const amount = Number(amountString);
Expand All @@ -21,9 +19,7 @@ export async function clearCommand(message: Message) {
message.channel
.bulkDelete(userMessages)
.then(() => {
message.reply(
`メッセージ${userMessages.length}件を削除しました\n(指定した数より削除した数が少ない場合があるのはDiscord側の仕様です)`
);
message.reply(`メッセージ${userMessages.length}件を削除しました\n(指定した数より削除した数が少ない場合があるのはDiscord側の仕様です)`);
})
.catch(() => {
message.reply('メッセージを削除できませんでした。');
Expand Down
6 changes: 2 additions & 4 deletions src/commands/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { embeds } from '../embeds';
import { ChannelType, Message, PermissionsBitField } from 'discord.js';

export async function inviteCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite))
return message.reply(embeds.PermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite))
return message.reply(embeds.invitePermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite)) return message.reply(embeds.PermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.CreateInstantInvite)) return message.reply(embeds.invitePermissionError);
if (message.channel.type !== ChannelType.GuildText) return;
message.channel
.createInvite()
Expand Down
3 changes: 1 addition & 2 deletions src/commands/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Message, Guild, TextBasedChannel, PermissionsBitField } from 'discord.j
import { writeFile, readFileSync } from 'fs';

export async function joinCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator))
return message.reply(embeds.PermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) return message.reply(embeds.PermissionError);
const args = message.content.split(' ');
const subcommand = args[1] as string | undefined;
switch (subcommand) {
Expand Down
6 changes: 2 additions & 4 deletions src/commands/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { embeds } from '../embeds';
import { PermissionsBitField, Message } from 'discord.js';

export async function kickCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.KickMembers))
return message.reply('コマンドを使用する権限がありません。');
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.KickMembers))
return message.reply(embeds.kickPermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.KickMembers)) return message.reply('コマンドを使用する権限がありません。');
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.KickMembers)) return message.reply(embeds.kickPermissionError);
const member = message.mentions.members?.first();
if (!member) return message.reply(embeds.kickHelp);
member
Expand Down
3 changes: 1 addition & 2 deletions src/commands/leave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Message, Guild, TextBasedChannel, PermissionsBitField } from 'discord.j
import { writeFile, readFileSync } from 'fs';

export async function leaveCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator))
return message.reply(embeds.PermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.Administrator)) return message.reply(embeds.PermissionError);
const args = message.content.split(' ');
const subcommand = args[1] as string | undefined;
switch (subcommand) {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Message, Guild, TextBasedChannel, PermissionsBitField } from 'discord.j
import { writeFile, readFileSync } from 'fs';

export async function logCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels))
return message.reply(embeds.PermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageChannels)) return message.reply(embeds.PermissionError);
const args = message.content.split(' ');
const subcommand = args[1];
switch (subcommand) {
Expand Down
5 changes: 1 addition & 4 deletions src/commands/ping.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Message, EmbedBuilder } from 'discord.js';

export async function pingCommand(message: Message) {
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle('Pong!:ping_pong:')
.setDescription(`${message.client.ws.ping}ms`);
const embed = new EmbedBuilder().setColor('#0099ff').setTitle('Pong!:ping_pong:').setDescription(`${message.client.ws.ping}ms`);
message.reply({ embeds: [embed] });
}
4 changes: 1 addition & 3 deletions src/commands/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ export async function pollCommand(message: Message) {
const [title, ...options] = args.slice(1);
if (!title || options.length === 0) return message.reply(embeds.pollHelp);
if (options.length > 10) return message.reply('選択肢は10個までです。');
const embed = new EmbedBuilder()
.setTitle(title)
.setDescription(options.map((option, index) => `${reactions[index]} ${option}`).join('\n'));
const embed = new EmbedBuilder().setTitle(title).setDescription(options.map((option, index) => `${reactions[index]} ${option}`).join('\n'));

const pollMessage = await message.reply({ embeds: [embed] });
options.forEach(async (_, index) => {
Expand Down
6 changes: 2 additions & 4 deletions src/commands/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Guild, Message, PermissionsBitField } from 'discord.js';
import { writeFile, readFileSync } from 'fs';

export async function responseCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages))
return message.reply(embeds.PermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageMessages)) return message.reply(embeds.PermissionError);
const args = message.content.split(' ');
const subcommand = args[1] as string | undefined;
switch (subcommand) {
Expand Down Expand Up @@ -42,8 +41,7 @@ export async function responseCommand(message: Message) {
const data: Record<string, ServerResponseData> = JSON.parse(rawData);
const serverData = data[serverId];
if (!keyword) return message.reply(embeds.responseRemoveHelp);
if (!serverData || !serverData[keyword])
return message.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`);
if (!serverData || !serverData[keyword]) return message.reply(`キーワード 「${keyword}」 のレスポンスは登録されていません。`);
delete serverData[keyword];

writeFile('./database/responses.json', JSON.stringify(data, null, 2), (err) => {
Expand Down
9 changes: 3 additions & 6 deletions src/commands/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import { embeds } from '../embeds';
import { Message, PermissionsBitField } from 'discord.js';

export async function roleCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageRoles))
return message.reply(embeds.PermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.ManageRoles)) return message.reply(embeds.PermissionError);
const subcommand = message.content.split(' ')[1];
switch (subcommand) {
case 'add':
{
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles))
return message.reply(embeds.roleAddPermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) return message.reply(embeds.roleAddPermissionError);
const role = message.mentions.roles.first();
const member = message.mentions.members?.first();
if (!role || !member) return message.reply(embeds.roleAddHelp);
Expand All @@ -25,8 +23,7 @@ export async function roleCommand(message: Message) {
break;
case 'remove':
{
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles))
return message.reply(embeds.remrolePermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ManageRoles)) return message.reply(embeds.remrolePermissionError);
const role = message.mentions.roles.first();
const member = message.mentions.members?.first();
if (!role || !member) return message.reply(embeds.remroleHelp);
Expand Down
4 changes: 1 addition & 3 deletions src/commands/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export async function serverCommand(message: Message) {
guild.channels.cache.filter((c) => c.type === ChannelType.GuildText).size
}\nボイスチャンネル数: ${
guild.channels.cache.filter((c) => c.type === ChannelType.GuildVoice).size
}\nカテゴリー数: ${guild.channels.cache.filter((c) => c.type === ChannelType.GuildCategory).size}\n絵文字数: ${
guild.emojis.cache.size
}`
}\nカテゴリー数: ${guild.channels.cache.filter((c) => c.type === ChannelType.GuildCategory).size}\n絵文字数: ${guild.emojis.cache.size}`
}
)
.setThumbnail(guild.iconURL());
Expand Down
6 changes: 2 additions & 4 deletions src/commands/timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { embeds } from '../embeds';
import { Message, PermissionsBitField } from 'discord.js';

export async function timeoutCommand(message: Message) {
if (!message.member?.permissions.has(PermissionsBitField.Flags.ModerateMembers))
return message.reply(embeds.PermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ModerateMembers))
return message.reply(embeds.timeoutPermissionError);
if (!message.member?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) return message.reply(embeds.PermissionError);
if (!message.guild?.members.me?.permissions.has(PermissionsBitField.Flags.ModerateMembers)) return message.reply(embeds.timeoutPermissionError);
const args = message.content.split(' ');
const member = message.mentions.members?.first();
const time = parseInt(args[2]);
Expand Down
Loading
Loading