add chat command for user
This commit is contained in:
parent
fddedac210
commit
b4742392a9
@ -1,6 +1,6 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import ConfigManager from '../controller/ConfigManager';
|
import EcoController from '../controller/EcoController';
|
||||||
import EcoManager from '../controller/EcoManager';
|
import { Command } from '.';
|
||||||
|
|
||||||
|
|
||||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||||
@ -11,8 +11,8 @@ export default {
|
|||||||
.setDescription('Alert to game')
|
.setDescription('Alert to game')
|
||||||
.addStringOption(opt => opt.setName("message").setDescription("Alert message").setRequired(true))
|
.addStringOption(opt => opt.setName("message").setDescription("Alert message").setRequired(true))
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
async execute(interaction) {
|
||||||
const ecoManager = new EcoManager(config)
|
const ecoController = new EcoController()
|
||||||
|
|
||||||
const message = interaction.options.getString('message')
|
const message = interaction.options.getString('message')
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = await ecoManager.Alert(message)
|
const status = await ecoController.Alert(message)
|
||||||
if (!!status && !status.Errored) {
|
if (!!status && !status.Errored) {
|
||||||
await interaction.followUp("Уведомление отправлено")
|
await interaction.followUp("Уведомление отправлено")
|
||||||
} else {
|
} else {
|
||||||
@ -36,4 +36,4 @@ export default {
|
|||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
} as Command
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import ConfigManager from '../controller/ConfigManager';
|
import EcoController from '../controller/EcoController';
|
||||||
import EcoManager from '../controller/EcoManager';
|
|
||||||
import { Pagination } from "pagination.djs"
|
import { Pagination } from "pagination.djs"
|
||||||
|
import { Command } from '.';
|
||||||
|
|
||||||
// const { Pagination } = require('pagination.djs');
|
// const { Pagination } = require('pagination.djs');
|
||||||
|
|
||||||
@ -13,28 +13,30 @@ export default {
|
|||||||
.setDescription('Exec command')
|
.setDescription('Exec command')
|
||||||
.addStringOption(opt => opt.setName("command").setDescription("Command").setRequired(true))
|
.addStringOption(opt => opt.setName("command").setDescription("Command").setRequired(true))
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||||
async execute(interaction: ChatInputCommandInteraction<"cached">, config: ConfigManager) {
|
async execute(interaction) {
|
||||||
const ecoManager = new EcoManager(config)
|
const i: ChatInputCommandInteraction<"cached"> = interaction as any
|
||||||
|
|
||||||
const command = interaction.options.getString('command')
|
const ecoController = new EcoController()
|
||||||
|
|
||||||
await interaction.deferReply({ ephemeral: true })
|
const command = i.options.getString('command')
|
||||||
|
|
||||||
|
await i.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!command) {
|
if (!command) {
|
||||||
await interaction.followUp(`Ошибка выполнения команды. 0`);
|
await interaction.followUp(`Ошибка выполнения команды.`);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = await ecoManager.Exec(command)
|
const status = await ecoController.Exec(command)
|
||||||
|
|
||||||
const pagination = new Pagination(interaction)
|
const pagination = new Pagination(i)
|
||||||
pagination.setLimit(20)
|
pagination.setLimit(20)
|
||||||
|
|
||||||
if (!!status && !status.Errored) {
|
if (!!status && !status.Errored) {
|
||||||
if (status.CommandMessages.filter(e => e.Type === "Notifications-Chat").length > 0) {
|
if (status.CommandMessages.filter(e => e.Type === "Notifications-Chat").length > 0) {
|
||||||
if (status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.length <= 2000)
|
if (status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.length <= 2000)
|
||||||
await interaction.followUp(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.substring(0, 2000) || "Команда выполнена")
|
await i.followUp(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.substring(0, 2000) || "Команда выполнена")
|
||||||
else {
|
else {
|
||||||
pagination.setDescriptions(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.split("\n"))
|
pagination.setDescriptions(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.split("\n"))
|
||||||
pagination.render();
|
pagination.render();
|
||||||
@ -44,7 +46,7 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
if (!!status && status.CommandMessages.filter(e => e.Type === "Notifications-Chat").length > 0)
|
if (!!status && status.CommandMessages.filter(e => e.Type === "Notifications-Chat").length > 0)
|
||||||
if (status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.length <= 2000)
|
if (status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.length <= 2000)
|
||||||
await interaction.followUp(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.substring(0, 2000) || "Команда выполнена")
|
await i.followUp(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.substring(0, 2000) || "Команда выполнена")
|
||||||
else {
|
else {
|
||||||
pagination.setDescriptions(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.split("\n"))
|
pagination.setDescriptions(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.split("\n"))
|
||||||
pagination.render();
|
pagination.render();
|
||||||
@ -58,4 +60,4 @@ export default {
|
|||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
} as Command
|
||||||
|
61
src/commands/Link.ts
Normal file
61
src/commands/Link.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
|
import ConfigController from '../controller/ConfigController';
|
||||||
|
import EcoController from '../controller/EcoController';
|
||||||
|
import { Command } from '.';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('link')
|
||||||
|
.setDescription('Link Discord and Game accaunt')
|
||||||
|
.setDescriptionLocalization("ru", "Связь Discord и Игрового аккаунта")
|
||||||
|
.addStringOption(opt => opt.setName("id").setDescription("Steam64 or SLG ID").setDescriptionLocalization("ru", "Steam64 or SLG ID").setRequired(true))
|
||||||
|
.addStringOption(opt => opt.setName("code").setDescription("Confirmation code").setDescriptionLocalization("ru", "Код подтверждения").setRequired(false)),
|
||||||
|
async execute(interaction) {
|
||||||
|
var id = interaction.options.getString('id')
|
||||||
|
var codeConfirmation = interaction.options.getString('code')
|
||||||
|
|
||||||
|
const ecoController = new EcoController()
|
||||||
|
|
||||||
|
const user = global.config.users.get(interaction.user.id)
|
||||||
|
const userCode = global.config.authCodes.get(interaction.user.id)
|
||||||
|
|
||||||
|
const userG = global.config.usersInGame.filter(u => u.SlgId === id || u.SteamId === id).length > 0 ?
|
||||||
|
global.config.usersInGame.filter(u => u.SlgId === id || u.SteamId === id)[0] : null
|
||||||
|
|
||||||
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
|
const code = Math.floor(1000 + Math.random() * 9000).toString();
|
||||||
|
const codeUser = Math.floor(1000 + Math.random() * 9000).toString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!!codeConfirmation && !!userG) {
|
||||||
|
if (userCode === codeConfirmation) {
|
||||||
|
global.config.users.set(interaction.user.id, userG)
|
||||||
|
global.config.authCodes.set(interaction.user.id, "-")
|
||||||
|
await interaction.followUp(`Аккаунт успешно привязан`)
|
||||||
|
} else {
|
||||||
|
await interaction.followUp(`Ошибка привязки аккаунта, проверьте введённые данные`)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
} else if (user === undefined && !!userG && user === undefined) {
|
||||||
|
const status = await ecoController.Message(`Для связи аккаунтов введите код ${code}, иначе проигнорируйте данное сообщение`, `ChatLink${codeUser}`, `@${userG.Name}`)
|
||||||
|
if (!!status && status.Success) {
|
||||||
|
await interaction.followUp(`Код отправлен в личные сообщения от пользователя ChatLink${codeUser}, для продолжения введите эту команду, указав код полученный в игре`)
|
||||||
|
} else {
|
||||||
|
await interaction.followUp("Ошибка отправки кода")
|
||||||
|
}
|
||||||
|
global.config.authCodes.set(interaction.user.id, code)
|
||||||
|
return
|
||||||
|
} else if (user !== undefined) {
|
||||||
|
await interaction.followUp("Ваш аккаунт уже привязан, для отвязки свяжитесь с администрацией")
|
||||||
|
} else if (!userG) {
|
||||||
|
await interaction.followUp("Такой пользователь не найден на сервере")
|
||||||
|
} else {
|
||||||
|
await interaction.followUp("Вы уже воспользовались данной функцией, обратитесь к администрации в случае возникновения проблемы")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
await interaction.editReply("Ошибка отправки кода")
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} as Command
|
@ -1,6 +1,7 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import ConfigManager from '../controller/ConfigManager';
|
import ConfigController from '../controller/ConfigController';
|
||||||
import EcoManager from '../controller/EcoManager';
|
import EcoController from '../controller/EcoController';
|
||||||
|
import { Command } from '.';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@ -10,8 +11,8 @@ export default {
|
|||||||
.addStringOption(opt => opt.setName("to").setDescription("Destination (#General,@User)").setRequired(true))
|
.addStringOption(opt => opt.setName("to").setDescription("Destination (#General,@User)").setRequired(true))
|
||||||
.addStringOption(opt => opt.setName("from").setDescription("Source").setRequired(false))
|
.addStringOption(opt => opt.setName("from").setDescription("Source").setRequired(false))
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
async execute(interaction) {
|
||||||
const ecoManager = new EcoManager(config)
|
const ecoController = new EcoController()
|
||||||
|
|
||||||
var message = interaction.options.getString('message')
|
var message = interaction.options.getString('message')
|
||||||
var from = interaction.options.getString('from')
|
var from = interaction.options.getString('from')
|
||||||
@ -28,7 +29,7 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = await ecoManager.Message(message, from, to)
|
const status = await ecoController.Message(message, from, to)
|
||||||
if (!!status && status.Success) {
|
if (!!status && status.Success) {
|
||||||
await interaction.followUp("Сообщение отправлено")
|
await interaction.followUp("Сообщение отправлено")
|
||||||
} else {
|
} else {
|
||||||
@ -40,4 +41,4 @@ export default {
|
|||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
} as Command
|
43
src/commands/UserMessage.ts
Normal file
43
src/commands/UserMessage.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
|
import ConfigController from '../controller/ConfigController';
|
||||||
|
import EcoController from '../controller/EcoController';
|
||||||
|
import { Command } from '.';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('msg')
|
||||||
|
.setDescription('Message to game')
|
||||||
|
.setDescriptionLocalization("ru", "Отправка сообщения в игровой чат")
|
||||||
|
.addStringOption(opt => opt.setName("message").setDescription("Message").setDescriptionLocalization("ru", "Сообщение").setRequired(true)),
|
||||||
|
async execute(interaction) {
|
||||||
|
const ecoController = new EcoController()
|
||||||
|
|
||||||
|
const user = global.config.users.get(interaction.user.id)
|
||||||
|
|
||||||
|
var message = interaction.options.getString('message')
|
||||||
|
|
||||||
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (user !== undefined) {
|
||||||
|
if (!message) {
|
||||||
|
await interaction.followUp(`Ошибка отправки сообщения`);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const status = await ecoController.Message(message, user.Name, `#${global.config.inGameChat}`)
|
||||||
|
if (!!status && status.Success) {
|
||||||
|
await interaction.followUp("Сообщение отправлено")
|
||||||
|
} else {
|
||||||
|
await interaction.followUp("Ошибка отправки сообщения")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
await interaction.followUp("Необходимо сначала связать аккаунты, для этого воспользуйтесь командой `/link`")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
await interaction.editReply("Ошибка отправки сообщения")
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} as Command
|
@ -1,4 +1,4 @@
|
|||||||
import { Collection } from 'discord.js'
|
import { AutocompleteInteraction, CacheType, ChatInputCommandInteraction, Collection, SlashCommandBuilder } from 'discord.js'
|
||||||
import syncUsers from './syncUsers'
|
import syncUsers from './syncUsers'
|
||||||
import Alert from './Alert'
|
import Alert from './Alert'
|
||||||
import Message from './Message'
|
import Message from './Message'
|
||||||
@ -6,8 +6,16 @@ import Exec from './Exec'
|
|||||||
import syncMessages from './syncMessages'
|
import syncMessages from './syncMessages'
|
||||||
import setChatChannelId from './setChatChannelId'
|
import setChatChannelId from './setChatChannelId'
|
||||||
import throwChatTimestamp from './throwChatTimestamp'
|
import throwChatTimestamp from './throwChatTimestamp'
|
||||||
|
import UserMessage from './UserMessage'
|
||||||
|
import Link from './Link'
|
||||||
|
|
||||||
const commands = new Collection
|
export type Command = {
|
||||||
|
data: SlashCommandBuilder;
|
||||||
|
execute(interaction: ChatInputCommandInteraction<CacheType>);
|
||||||
|
autocomplete?(interaction: AutocompleteInteraction<CacheType>);
|
||||||
|
}
|
||||||
|
|
||||||
|
const commands = new Collection<string, Command>()
|
||||||
|
|
||||||
commands.set(syncUsers.data.name, syncUsers)
|
commands.set(syncUsers.data.name, syncUsers)
|
||||||
commands.set(Alert.data.name, Alert)
|
commands.set(Alert.data.name, Alert)
|
||||||
@ -16,5 +24,7 @@ commands.set(Exec.data.name, Exec)
|
|||||||
commands.set(syncMessages.data.name, syncMessages)
|
commands.set(syncMessages.data.name, syncMessages)
|
||||||
commands.set(setChatChannelId.data.name, setChatChannelId)
|
commands.set(setChatChannelId.data.name, setChatChannelId)
|
||||||
commands.set(throwChatTimestamp.data.name, throwChatTimestamp)
|
commands.set(throwChatTimestamp.data.name, throwChatTimestamp)
|
||||||
|
commands.set(UserMessage.data.name, UserMessage)
|
||||||
|
commands.set(Link.data.name, Link)
|
||||||
|
|
||||||
export default commands
|
export default commands
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import ConfigManager from '../controller/ConfigManager';
|
import { Command } from '.';
|
||||||
import ChatController from '../controller/ChatController';
|
|
||||||
import { error } from 'console';
|
|
||||||
|
|
||||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||||
|
|
||||||
@ -10,7 +8,7 @@ export default {
|
|||||||
.setName('set_chat_channel')
|
.setName('set_chat_channel')
|
||||||
.setDescription('set chat channel')
|
.setDescription('set chat channel')
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
async execute(interaction) {
|
||||||
|
|
||||||
await interaction.deferReply({ ephemeral: true })
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
@ -33,4 +31,4 @@ export default {
|
|||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
} as Command
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import ConfigManager from '../controller/ConfigManager';
|
import ConfigController from '../controller/ConfigController';
|
||||||
import ChatController from '../controller/ChatController';
|
import ChatController from '../controller/ChatController';
|
||||||
|
import { Command } from '.';
|
||||||
|
|
||||||
|
|
||||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||||
@ -10,8 +11,8 @@ export default {
|
|||||||
.setName('sync_messages')
|
.setName('sync_messages')
|
||||||
.setDescription('Sync all messages')
|
.setDescription('Sync all messages')
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
async execute(interaction) {
|
||||||
const chatController = new ChatController(config)
|
const chatController = new ChatController()
|
||||||
|
|
||||||
await interaction.deferReply({ ephemeral: true })
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
@ -31,4 +32,4 @@ export default {
|
|||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
} as Command
|
@ -1,6 +1,6 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import ConfigManager from '../controller/ConfigManager';
|
import UserController from '../controller/UserController';
|
||||||
import UserManager from '../controller/UserManager';
|
import { Command } from '.';
|
||||||
|
|
||||||
|
|
||||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||||
@ -10,13 +10,13 @@ export default {
|
|||||||
.setName('sync_users')
|
.setName('sync_users')
|
||||||
.setDescription('Sync users')
|
.setDescription('Sync users')
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
async execute(interaction) {
|
||||||
const userManager = new UserManager(config)
|
const userController = new UserController()
|
||||||
|
|
||||||
await interaction.deferReply({ ephemeral: true })
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const sync = await userManager.sync()
|
const sync = await userController.sync()
|
||||||
if (sync) {
|
if (sync) {
|
||||||
await interaction.followUp("Успешно")
|
await interaction.followUp("Успешно")
|
||||||
} else {
|
} else {
|
||||||
@ -31,4 +31,4 @@ export default {
|
|||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
} as Command
|
||||||
|
26
src/commands/throwChatConnections.ts
Normal file
26
src/commands/throwChatConnections.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
|
import { Command } from '.';
|
||||||
|
import UserI from '../types/UserI';
|
||||||
|
|
||||||
|
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('throw_chat_connections')
|
||||||
|
.setDescription('throw chat connections')
|
||||||
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||||
|
async execute(interaction) {
|
||||||
|
|
||||||
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
|
try {
|
||||||
|
global.config.users = new Map<string, UserI>()
|
||||||
|
|
||||||
|
await interaction.followUp("Связи аккаунтов удалены")
|
||||||
|
return
|
||||||
|
} catch (error) {
|
||||||
|
await interaction.editReply("Ошибка удаления связей аккаунтов")
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
} as Command
|
@ -1,7 +1,5 @@
|
|||||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import ConfigManager from '../controller/ConfigManager';
|
import { Command } from '.';
|
||||||
import ChatController from '../controller/ChatController';
|
|
||||||
import { error } from 'console';
|
|
||||||
|
|
||||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||||
|
|
||||||
@ -10,7 +8,7 @@ export default {
|
|||||||
.setName('throw_chat_timestamp')
|
.setName('throw_chat_timestamp')
|
||||||
.setDescription('throw chat timestamp')
|
.setDescription('throw chat timestamp')
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
async execute(interaction) {
|
||||||
|
|
||||||
await interaction.deferReply({ ephemeral: true })
|
await interaction.deferReply({ ephemeral: true })
|
||||||
|
|
||||||
@ -24,4 +22,4 @@ export default {
|
|||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
} as Command
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CacheType, ChatInputCommandInteraction, EmbedBuilder, Message } from "discord.js";
|
|
||||||
import ConfigManager from "./ConfigManager";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import UserI from "../types/UserI";
|
|
||||||
import MessageI from "../types/MessageI";
|
import MessageI from "../types/MessageI";
|
||||||
import { channel } from "diagnostics_channel";
|
|
||||||
|
|
||||||
var isSyncing = false
|
var isSyncing = false
|
||||||
|
|
||||||
@ -70,9 +66,12 @@ export default class ChatController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
messages.forEach(async m => {
|
messages.forEach(async m => {
|
||||||
|
if (m.Receiver in ["Общий", "General"] && m.Receiver !== global.config.inGameChat)
|
||||||
|
global.config.inGameChat = m.Receiver
|
||||||
if (global.config.messageTime !== m.Timestamp) {
|
if (global.config.messageTime !== m.Timestamp) {
|
||||||
if (global.config.messageTime < m.Timestamp)
|
if (global.config.messageTime < m.Timestamp)
|
||||||
global.config.messageTime = m.Timestamp
|
global.config.messageTime = m.Timestamp
|
||||||
|
|
||||||
// const me = new EmbedBuilder()
|
// const me = new EmbedBuilder()
|
||||||
// me.setDescription(m.Text)
|
// me.setDescription(m.Text)
|
||||||
// me.setAuthor({ name: m.Sender })
|
// me.setAuthor({ name: m.Sender })
|
||||||
|
@ -2,29 +2,23 @@ import path from "path";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import UserI from "../types/UserI";
|
import UserI from "../types/UserI";
|
||||||
import { ServerInfoI } from "../types/ServerInfoI";
|
import { ServerInfoI } from "../types/ServerInfoI";
|
||||||
import MessageI from "../types/MessageI";
|
|
||||||
|
|
||||||
interface ConfigManagerI {
|
interface ConfigControllerI {
|
||||||
userManager?: {
|
users: { name: string, value: UserI }[];
|
||||||
users: UserI[];
|
usersInGame: UserI[];
|
||||||
authCodes: Date[];
|
|
||||||
};
|
|
||||||
messages?: MessageI[];
|
|
||||||
messageTime: number;
|
messageTime: number;
|
||||||
|
inGameChat: string;
|
||||||
serverInfo?: ServerInfoI;
|
serverInfo?: ServerInfoI;
|
||||||
chatChannelId?: string;
|
chatChannelId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ConfigManager {
|
export default class ConfigController {
|
||||||
configPath = path.join(process.env.STORAGE || "/app/storage", "config.json")
|
configPath = path.join(process.env.STORAGE || "/app/storage", "config.json")
|
||||||
public userManager: {
|
public usersInGame: UserI[] = [];
|
||||||
users: UserI[];
|
public users: Map<string, UserI> = new Map<string, UserI>();
|
||||||
authCodes: Date[];
|
public authCodes: Map<string, string> = new Map<string, string>();
|
||||||
} = {
|
|
||||||
users: [],
|
|
||||||
authCodes: [],
|
|
||||||
}
|
|
||||||
public chatChannelId: string = ""
|
public chatChannelId: string = ""
|
||||||
|
public inGameChat: string = "General"
|
||||||
public messageTime: number = 0
|
public messageTime: number = 0
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -32,27 +26,33 @@ export default class ConfigManager {
|
|||||||
setInterval(() => this.save(), 10000)
|
setInterval(() => this.save(), 10000)
|
||||||
}
|
}
|
||||||
save() {
|
save() {
|
||||||
const r: ConfigManagerI = {
|
const r: ConfigControllerI = {
|
||||||
userManager: this.userManager,
|
users: Array.from(this.users, ([name, value]) => ({ name, value })),
|
||||||
chatChannelId: this.chatChannelId,
|
chatChannelId: this.chatChannelId,
|
||||||
messageTime: this.messageTime,
|
messageTime: this.messageTime,
|
||||||
|
inGameChat: this.inGameChat,
|
||||||
|
usersInGame: this.usersInGame,
|
||||||
}
|
}
|
||||||
fs.writeFileSync(this.configPath, JSON.stringify(r))
|
fs.writeFileSync(this.configPath, JSON.stringify(r))
|
||||||
}
|
}
|
||||||
load() {
|
load() {
|
||||||
const r = {
|
const r = {
|
||||||
userManager: this.userManager,
|
users: this.users,
|
||||||
chatChannelId: this.chatChannelId,
|
messageTime: this.messageTime,
|
||||||
}
|
}
|
||||||
if (!fs.existsSync(this.configPath)) {
|
if (!fs.existsSync(this.configPath)) {
|
||||||
fs.writeFileSync(this.configPath, JSON.stringify(r))
|
fs.writeFileSync(this.configPath, JSON.stringify(r))
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const t: ConfigManagerI = JSON.parse(String(fs.readFileSync(this.configPath)))
|
const t: ConfigControllerI = JSON.parse(String(fs.readFileSync(this.configPath)))
|
||||||
if (!!t?.userManager)
|
if (!!t?.users)
|
||||||
this.userManager = { ...this.userManager, ...t.userManager }
|
this.users = new Map<string, UserI>(t.users.map(v => [v.name, v.value]))
|
||||||
|
if (!!t?.usersInGame)
|
||||||
|
this.usersInGame = t.usersInGame
|
||||||
if (!!t?.messageTime)
|
if (!!t?.messageTime)
|
||||||
this.messageTime = t.messageTime
|
this.messageTime = t.messageTime
|
||||||
|
if (!!t?.inGameChat)
|
||||||
|
this.inGameChat = t.inGameChat
|
||||||
if (!!t?.chatChannelId)
|
if (!!t?.chatChannelId)
|
||||||
this.chatChannelId = t.chatChannelId
|
this.chatChannelId = t.chatChannelId
|
||||||
} catch (error) {
|
} catch (error) {
|
@ -1,15 +1,8 @@
|
|||||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CacheType, ChatInputCommandInteraction, Message } from "discord.js";
|
|
||||||
import ConfigManager from "./ConfigManager";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import UserI from "../types/UserI";
|
|
||||||
import CommandReplyI from "../types/CommandReplyI";
|
import CommandReplyI from "../types/CommandReplyI";
|
||||||
import MessageReplyI from "../types/MessageReplyI";
|
import MessageReplyI from "../types/MessageReplyI";
|
||||||
|
|
||||||
export default class EcoManager {
|
export default class EcoController {
|
||||||
config: ConfigManager
|
|
||||||
public constructor(config: ConfigManager) {
|
|
||||||
this.config = config
|
|
||||||
}
|
|
||||||
public async Alert(message: string) {
|
public async Alert(message: string) {
|
||||||
if (!message) return null
|
if (!message) return null
|
||||||
return await this.Exec(`manage alert ${message}`)
|
return await this.Exec(`manage alert ${message}`)
|
@ -1,13 +1,7 @@
|
|||||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CacheType, ChatInputCommandInteraction, Message } from "discord.js";
|
|
||||||
import ConfigManager from "./ConfigManager";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import UserI from "../types/UserI";
|
import UserI from "../types/UserI";
|
||||||
|
|
||||||
export default class UserManager {
|
export default class UserController {
|
||||||
config: ConfigManager
|
|
||||||
public constructor(config: ConfigManager) {
|
|
||||||
this.config = config
|
|
||||||
}
|
|
||||||
public async sync() {
|
public async sync() {
|
||||||
try {
|
try {
|
||||||
const { data, status } = await axios.get<UserI[]>(`${process.env.ECO_API_BASE || "https://eco.kamgames.xyz"}/api/v1/users`, {
|
const { data, status } = await axios.get<UserI[]>(`${process.env.ECO_API_BASE || "https://eco.kamgames.xyz"}/api/v1/users`, {
|
||||||
@ -19,7 +13,7 @@ export default class UserManager {
|
|||||||
|
|
||||||
if (status !== 200) return false
|
if (status !== 200) return false
|
||||||
|
|
||||||
this.config.userManager.users = data
|
global.config.usersInGame = data
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} catch (error) {
|
} catch (error) {
|
75
src/index.ts
75
src/index.ts
@ -1,11 +1,12 @@
|
|||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import { ActivityType, Client, Events, GatewayIntentBits, Partials } from 'discord.js'
|
import { ActivityType, Client, Events, GatewayIntentBits, Partials } from 'discord.js'
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import ConfigManager from './controller/ConfigManager';
|
import ConfigController from './controller/ConfigController';
|
||||||
import updateCommands from './updateCommands';
|
import updateCommands from './updateCommands';
|
||||||
import commands from './commands';
|
import commands from './commands';
|
||||||
import { ServerInfoI } from './types/ServerInfoI';
|
import { ServerInfoI } from './types/ServerInfoI';
|
||||||
import ChatController from './controller/ChatController';
|
import ChatController from './controller/ChatController';
|
||||||
|
import UserController from './controller/UserController';
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
@ -25,11 +26,12 @@ const client = new Client({
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
var client: Client<boolean>;
|
var client: Client<boolean>;
|
||||||
var config: ConfigManager;
|
var config: ConfigController;
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = new ConfigManager()
|
const config = new ConfigController()
|
||||||
const chatController = new ChatController()
|
const chatController = new ChatController()
|
||||||
|
const userController = new UserController()
|
||||||
|
|
||||||
global.client = client
|
global.client = client
|
||||||
global.config = config
|
global.config = config
|
||||||
@ -39,6 +41,7 @@ client.on('ready', () => {
|
|||||||
updateServerData();
|
updateServerData();
|
||||||
setInterval(updateServerData, 10000)
|
setInterval(updateServerData, 10000)
|
||||||
setInterval(() => { chatController.syncMessageWithDiscord() }, 2000)
|
setInterval(() => { chatController.syncMessageWithDiscord() }, 2000)
|
||||||
|
setInterval(() => { userController.sync() }, 10000)
|
||||||
});
|
});
|
||||||
|
|
||||||
async function updateServerData() {
|
async function updateServerData() {
|
||||||
@ -63,7 +66,7 @@ client.on(Events.InteractionCreate, async interaction => {
|
|||||||
try {
|
try {
|
||||||
if (interaction.isChatInputCommand()) {
|
if (interaction.isChatInputCommand()) {
|
||||||
|
|
||||||
const command: any = commands.get(interaction.commandName);
|
const command = commands.get(interaction.commandName);
|
||||||
|
|
||||||
if (!command) {
|
if (!command) {
|
||||||
console.log(`No command matching ${interaction.commandName} was found.`);
|
console.log(`No command matching ${interaction.commandName} was found.`);
|
||||||
@ -71,7 +74,7 @@ client.on(Events.InteractionCreate, async interaction => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await command.execute(interaction, config);
|
await command.execute(interaction);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.log(`Error executing ${interaction.commandName}`);
|
// console.log(`Error executing ${interaction.commandName}`);
|
||||||
// console.log(error);
|
// console.log(error);
|
||||||
@ -85,7 +88,21 @@ client.on(Events.InteractionCreate, async interaction => {
|
|||||||
|
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
} else
|
} else if (interaction.isAutocomplete()) {
|
||||||
|
const command = commands.get(interaction.commandName);
|
||||||
|
|
||||||
|
if (!command) {
|
||||||
|
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (command.autocomplete !== undefined)
|
||||||
|
await command.autocomplete(interaction);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.log(error)
|
// console.log(error)
|
||||||
@ -93,53 +110,9 @@ client.on(Events.InteractionCreate, async interaction => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// client.on(Events.MessageReactionAdd, async (r, u) => {
|
|
||||||
// try {
|
|
||||||
// console.log(r)
|
|
||||||
// console.log(u)
|
|
||||||
// const g = r.message.guildId === config.guildId
|
|
||||||
// const c = r.message.channelId === config.roleManager.channelId
|
|
||||||
// const m = r.message.id === config.roleManager.messageId
|
|
||||||
// const notBotAndSystem = !u.bot && !u.system
|
|
||||||
// if (m && g && c && notBotAndSystem) {
|
|
||||||
// const react: string = (r as any)._emoji.name
|
|
||||||
// const roleArr = config.roleManager.roles.filter(r => r.emoji === react)
|
|
||||||
// if (!!roleArr.length) {
|
|
||||||
// const role = roleArr[0]
|
|
||||||
// const guild = client.guilds.cache.get(String(config.guildId))
|
|
||||||
// await guild?.members.addRole({
|
|
||||||
// user: u.id,
|
|
||||||
// role: role.roleId
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } catch (error) { console.log(error) }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// client.on(Events.MessageReactionRemove, async (r, u) => {
|
|
||||||
// try {
|
|
||||||
// const g = r.message.guildId === config.guildId
|
|
||||||
// const c = r.message.channelId === config.roleManager.channelId
|
|
||||||
// const m = r.message.id === config.roleManager.messageId
|
|
||||||
// const notBotAndSystem = !u.bot && !u.system
|
|
||||||
// if (m && g && c && notBotAndSystem) {
|
|
||||||
// const react: string = (r as any)._emoji.name
|
|
||||||
// const roleArr = config.roleManager.roles.filter(r => r.emoji === react)
|
|
||||||
// if (!!roleArr.length) {
|
|
||||||
// var role = roleArr[0]
|
|
||||||
// const guild = client.guilds.cache.get(String(config.guildId))
|
|
||||||
// await guild?.members.removeRole({
|
|
||||||
// user: u.id,
|
|
||||||
// role: role.roleId
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } catch (error) { console.log(error) }
|
|
||||||
// })
|
|
||||||
|
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
client.login(process.env.DISCORD_TOKEN);
|
||||||
|
|
||||||
updateCommands(config)
|
updateCommands()
|
||||||
if (!!process.env.DISCORD_TOKEN)
|
if (!!process.env.DISCORD_TOKEN)
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
client.login(process.env.DISCORD_TOKEN);
|
||||||
else
|
else
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { REST } from "@discordjs/rest";
|
import { REST } from "@discordjs/rest";
|
||||||
import { Routes } from "discord.js";
|
import { PermissionFlagsBits, Routes } from "discord.js";
|
||||||
import com from './commands'
|
import com, { Command } from './commands'
|
||||||
import ConfigManager from "./controller/ConfigManager";
|
|
||||||
|
|
||||||
export default function updateCommands(config: ConfigManager) {
|
export default function updateCommands() {
|
||||||
const commands: any = []
|
const commands: Command[] = []
|
||||||
|
const commandsGlobal: Command[] = []
|
||||||
|
|
||||||
if (!process.env.DISCORD_TOKEN)
|
if (!process.env.DISCORD_TOKEN)
|
||||||
throw new Error("Token is null");
|
throw new Error("Token is null");
|
||||||
|
|
||||||
com.forEach((command: any) => {
|
com.forEach((command) => {
|
||||||
commands.push(command.data.toJSON() as never)
|
commands.push(command.data.toJSON() as never)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user