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

バグ修正とか新機能(多分そのうち追加する奴)とか #40

Merged
merged 7 commits into from
Feb 20, 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 src/Events/onInteractionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ config();
export async function onInteractionCreate(interaction: BaseInteraction): Promise<Awaitable<void>> {
if (interaction.isAutocomplete()) {
switch (interaction.commandName) {
case 'resdelete':
case 'response':
interactions.responseComplete(interaction);
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/Events/onMessageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { config } from 'dotenv';

config();

const prefix = 'mt!';
const prefix = 'mc!';

export async function onMessageCreate(message: Message): Promise<Awaitable<void>> {
if (bannedUsers.includes(message.author.id)) return;
Expand Down
3 changes: 2 additions & 1 deletion src/Events/onMessageDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export async function onMessageDelete(message: Message | PartialMessage) {
!message.content ||
!message.guild?.members.me?.permissionsIn(message.channel as GuildBasedChannel).has(PermissionsBitField.Flags.SendMessages) ||
!message.guild ||
bannedUsers.includes((message.author as User).id) || bannedServers.includes((message.guild as Guild).id)
bannedUsers.includes((message.author as User).id) ||
bannedServers.includes((message.guild as Guild).id)
)
return;
await connect(process.env.MONGO_URL!);
Expand Down
9 changes: 8 additions & 1 deletion src/Events/onMessageUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { config } from 'dotenv';
config();

export const onMessageUpdate = async (oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage) => {
if ((oldMessage.author as User).bot || oldMessage.content === newMessage.content || !oldMessage.guild || 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 ||
bannedUsers.includes((newMessage.author as User).id) ||
bannedServers.includes((newMessage.guild as Guild).id)
)
return;
await connect(process.env.MONGO_URL!);
const MessageLog = new Database('MessageLog');
list['message'] = await MessageLog.keys();
Expand Down
43 changes: 0 additions & 43 deletions src/Utils/ServerData.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/commands/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Message, EmbedBuilder } from 'discord.js';

export async function bannerCommand(message: Message) {
const user = message.mentions.users.first() || message.author;
const banner = user.bannerURL({ size: 1024 });
const targetUser = await message.client.users.fetch(user.id, { force: true });
const banner = targetUser.bannerURL({ size: 1024 });
if (!banner) return message.reply('バナーが設定されていませんでした。');
const embed = new EmbedBuilder().setTitle(`${user.username}のバナー`).setImage(banner).setColor('#0099ff');
const embed = new EmbedBuilder().setTitle(`${user.displayName}のバナー`).setImage(banner).setColor('#0099ff');
message.reply({ embeds: [embed] });
return;
}
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { events } from './Events';
import { userEnCounts } from './interactions/context_en_translate';
import { userJaCounts } from './interactions/context_ja_translate';
import { BaseInteraction, Client, GatewayIntentBits, GuildMember, Message, PartialGuildMember, PartialMessage, Partials, Role } from 'discord.js';
import { config } from 'dotenv';
import cron from 'node-cron';
import { userJaCounts } from './interactions/context_ja_translate';
import { userEnCounts } from './interactions/context_en_translate';

config();

Expand Down Expand Up @@ -44,9 +44,9 @@ client
.on('guildMemberAdd', async (member: GuildMember) => events.onGuildMemberAdd(member))
.on('guildMemberRemove', async (member: GuildMember | PartialGuildMember) => events.onGuildMemberRemove(member))
.on('guildMemberUpdate', async (oldMember: GuildMember | PartialGuildMember, newMember: GuildMember) => events.onGuildMemberUpdate(oldMember, newMember))
.on('guildRoleCreate', async (role: Role) => events.onGuildRoleCreate(role))
.on('guildRoleUpdate', async (oldRole: Role, newRole: Role) => events.onGuildRoleUpdate(oldRole, newRole))
.on('guildRoleDelete', async (role: Role) => events.onGuildRoleDelete(role))
.on('roleCreate', async (role: Role) => events.onGuildRoleCreate(role))
.on('roleUpdate', async (oldRole: Role, newRole: Role) => events.onGuildRoleUpdate(oldRole, newRole))
.on('roleDelete', async (role: Role) => events.onGuildRoleDelete(role))
.on('interactionCreate', async (interaction: BaseInteraction) => events.onInteractionCreate(interaction))
.on('error', async (error: Error) => events.onError(client, error))
.login(process.env.TOKEN);
3 changes: 2 additions & 1 deletion src/interactions/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';

export async function bannerCommand(interaction: ChatInputCommandInteraction) {
const user = interaction.options.getUser('user') || interaction.user;
const banner = user.bannerURL({ size: 1024 });
const targetUser = await interaction.client.users.fetch(user.id, { force: true });
const banner = targetUser.bannerURL({ size: 1024 });
if (!banner) return interaction.reply({ content: 'このユーザーにはバナーがありません。', ephemeral: true });
const embed = new EmbedBuilder().setTitle(`${user.username}のバナー`).setImage(banner).setColor('#0099ff');
interaction.reply({ embeds: [embed] });
Expand Down
29 changes: 19 additions & 10 deletions src/interactions/response_complete.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { ServerResponseData } from '../Utils/ServerData';
import { list } from '../index';
import { connect, Database } from 'aurora-mongo';
import { AutocompleteInteraction, Guild } from 'discord.js';
import { readFileSync } from 'fs';

export async function responseComplete(interaction: AutocompleteInteraction) {
const focusedValue = interaction.options.getFocused();
const rawData = readFileSync('./database/responses.json', 'utf-8');
const data: Record<string, ServerResponseData> = JSON.parse(rawData);
const choices = [] as string[];
const serverData = data[(interaction.guild as Guild).id];
if (!serverData || Object.keys(serverData).length === 0) return;
Object.keys(data[(interaction.guild as Guild).id]).forEach((key) => {
choices.push(key);
});
await connect(process.env.MONGO_URL!);
const Response = new Database('Response');
list['response'] = await Response.keys();
const matchingKeys = list['response'].filter((key) => key.split(',')[0] === (interaction.guild as Guild).id);
const serverData: { [key: string]: string } = {};
await Promise.all(
matchingKeys.map(async (key) => {
const value = await Response.get(key);
serverData[key] = value;
})
);
const choices: string[] = [];
for (const key in serverData) {
const response = serverData[key];
choices.push(response);
}

const filtered = choices.filter((choice) => choice.startsWith(focusedValue));
await interaction.respond(filtered.map((choice) => ({ name: choice, value: choice })));
}
Loading