From fddedac210ebf58ff93085351e567e5d2a8ac19e Mon Sep 17 00:00:00 2001 From: The-Foxon Date: Fri, 14 Jul 2023 00:42:09 +1200 Subject: [PATCH] small fixes and add chat timestamp thrw command --- src/commands/index.ts | 2 ++ src/commands/throwChatTimestamp.ts | 27 +++++++++++++++++++++++++++ src/controller/ChatController.ts | 17 +++++++++-------- 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 src/commands/throwChatTimestamp.ts diff --git a/src/commands/index.ts b/src/commands/index.ts index ae5c129..59dea2a 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -5,6 +5,7 @@ import Message from './Message' import Exec from './Exec' import syncMessages from './syncMessages' import setChatChannelId from './setChatChannelId' +import throwChatTimestamp from './throwChatTimestamp' const commands = new Collection @@ -14,5 +15,6 @@ commands.set(Message.data.name, Message) commands.set(Exec.data.name, Exec) commands.set(syncMessages.data.name, syncMessages) commands.set(setChatChannelId.data.name, setChatChannelId) +commands.set(throwChatTimestamp.data.name, throwChatTimestamp) export default commands diff --git a/src/commands/throwChatTimestamp.ts b/src/commands/throwChatTimestamp.ts new file mode 100644 index 0000000..bd4ce80 --- /dev/null +++ b/src/commands/throwChatTimestamp.ts @@ -0,0 +1,27 @@ +import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; +import ConfigManager from '../controller/ConfigManager'; +import ChatController from '../controller/ChatController'; +import { error } from 'console'; + +// const adminPermissions = new PermissionsBitField('Administrator'); + +export default { + data: new SlashCommandBuilder() + .setName('throw_chat_timestamp') + .setDescription('throw chat timestamp') + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), + async execute(interaction: ChatInputCommandInteraction, config: ConfigManager) { + + await interaction.deferReply({ ephemeral: true }) + + try { + global.config.messageTime = 0 + + await interaction.followUp("Время сброшено") + return + } catch (error) { + await interaction.editReply("Ошибка сброса времени") + console.log(error) + } + }, +}; diff --git a/src/controller/ChatController.ts b/src/controller/ChatController.ts index d557cf1..6abf489 100644 --- a/src/controller/ChatController.ts +++ b/src/controller/ChatController.ts @@ -70,14 +70,15 @@ export default class ChatController { } messages.forEach(async m => { - if (global.config.messageTime < m.Timestamp) - global.config.messageTime = m.Timestamp - // const me = new EmbedBuilder() - // me.setDescription(m.Text) - // me.setAuthor({ name: m.Sender }) - // ch.send({ embeds: [me] }) - console.log(`${m.Sender}: ${m.Text}`) - await ch.send(`**${m.Sender}**: ${m.Text}`) + if (global.config.messageTime !== m.Timestamp) { + if (global.config.messageTime < m.Timestamp) + global.config.messageTime = m.Timestamp + // const me = new EmbedBuilder() + // me.setDescription(m.Text) + // me.setAuthor({ name: m.Sender }) + // ch.send({ embeds: [me] }) + await ch.send(`**${m.Sender}**: ${m.Text}`) + } }) isSyncing = false