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 ConfigManager from '../controller/ConfigManager';
|
||||
import EcoManager from '../controller/EcoManager';
|
||||
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import EcoController from '../controller/EcoController';
|
||||
import { Command } from '.';
|
||||
|
||||
|
||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||
@ -11,8 +11,8 @@ export default {
|
||||
.setDescription('Alert to game')
|
||||
.addStringOption(opt => opt.setName("message").setDescription("Alert message").setRequired(true))
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
||||
const ecoManager = new EcoManager(config)
|
||||
async execute(interaction) {
|
||||
const ecoController = new EcoController()
|
||||
|
||||
const message = interaction.options.getString('message')
|
||||
|
||||
@ -24,7 +24,7 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
const status = await ecoManager.Alert(message)
|
||||
const status = await ecoController.Alert(message)
|
||||
if (!!status && !status.Errored) {
|
||||
await interaction.followUp("Уведомление отправлено")
|
||||
} else {
|
||||
@ -36,4 +36,4 @@ export default {
|
||||
console.log(error)
|
||||
}
|
||||
},
|
||||
};
|
||||
} as Command
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import ConfigManager from '../controller/ConfigManager';
|
||||
import EcoManager from '../controller/EcoManager';
|
||||
import { ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import EcoController from '../controller/EcoController';
|
||||
import { Pagination } from "pagination.djs"
|
||||
import { Command } from '.';
|
||||
|
||||
// const { Pagination } = require('pagination.djs');
|
||||
|
||||
@ -13,28 +13,30 @@ export default {
|
||||
.setDescription('Exec command')
|
||||
.addStringOption(opt => opt.setName("command").setDescription("Command").setRequired(true))
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
async execute(interaction: ChatInputCommandInteraction<"cached">, config: ConfigManager) {
|
||||
const ecoManager = new EcoManager(config)
|
||||
async execute(interaction) {
|
||||
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 {
|
||||
if (!command) {
|
||||
await interaction.followUp(`Ошибка выполнения команды. 0`);
|
||||
await interaction.followUp(`Ошибка выполнения команды.`);
|
||||
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)
|
||||
|
||||
if (!!status && !status.Errored) {
|
||||
if (status.CommandMessages.filter(e => e.Type === "Notifications-Chat").length > 0) {
|
||||
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 {
|
||||
pagination.setDescriptions(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.split("\n"))
|
||||
pagination.render();
|
||||
@ -44,7 +46,7 @@ export default {
|
||||
} else {
|
||||
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)
|
||||
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 {
|
||||
pagination.setDescriptions(status.CommandMessages.filter(e => e.Type === "Notifications-Chat")[0].Message.split("\n"))
|
||||
pagination.render();
|
||||
@ -58,4 +60,4 @@ export default {
|
||||
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 ConfigManager from '../controller/ConfigManager';
|
||||
import EcoManager from '../controller/EcoManager';
|
||||
import ConfigController from '../controller/ConfigController';
|
||||
import EcoController from '../controller/EcoController';
|
||||
import { Command } from '.';
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
@ -10,8 +11,8 @@ export default {
|
||||
.addStringOption(opt => opt.setName("to").setDescription("Destination (#General,@User)").setRequired(true))
|
||||
.addStringOption(opt => opt.setName("from").setDescription("Source").setRequired(false))
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
||||
const ecoManager = new EcoManager(config)
|
||||
async execute(interaction) {
|
||||
const ecoController = new EcoController()
|
||||
|
||||
var message = interaction.options.getString('message')
|
||||
var from = interaction.options.getString('from')
|
||||
@ -28,7 +29,7 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
const status = await ecoManager.Message(message, from, to)
|
||||
const status = await ecoController.Message(message, from, to)
|
||||
if (!!status && status.Success) {
|
||||
await interaction.followUp("Сообщение отправлено")
|
||||
} else {
|
||||
@ -40,4 +41,4 @@ export default {
|
||||
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 Alert from './Alert'
|
||||
import Message from './Message'
|
||||
@ -6,8 +6,16 @@ import Exec from './Exec'
|
||||
import syncMessages from './syncMessages'
|
||||
import setChatChannelId from './setChatChannelId'
|
||||
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(Alert.data.name, Alert)
|
||||
@ -16,5 +24,7 @@ commands.set(Exec.data.name, Exec)
|
||||
commands.set(syncMessages.data.name, syncMessages)
|
||||
commands.set(setChatChannelId.data.name, setChatChannelId)
|
||||
commands.set(throwChatTimestamp.data.name, throwChatTimestamp)
|
||||
commands.set(UserMessage.data.name, UserMessage)
|
||||
commands.set(Link.data.name, Link)
|
||||
|
||||
export default commands
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import ConfigManager from '../controller/ConfigManager';
|
||||
import ChatController from '../controller/ChatController';
|
||||
import { error } from 'console';
|
||||
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { Command } from '.';
|
||||
|
||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||
|
||||
@ -10,7 +8,7 @@ export default {
|
||||
.setName('set_chat_channel')
|
||||
.setDescription('set chat channel')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
||||
async execute(interaction) {
|
||||
|
||||
await interaction.deferReply({ ephemeral: true })
|
||||
|
||||
@ -33,4 +31,4 @@ export default {
|
||||
console.log(error)
|
||||
}
|
||||
},
|
||||
};
|
||||
} as Command
|
||||
|
@ -1,6 +1,7 @@
|
||||
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 { Command } from '.';
|
||||
|
||||
|
||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||
@ -10,8 +11,8 @@ export default {
|
||||
.setName('sync_messages')
|
||||
.setDescription('Sync all messages')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
||||
const chatController = new ChatController(config)
|
||||
async execute(interaction) {
|
||||
const chatController = new ChatController()
|
||||
|
||||
await interaction.deferReply({ ephemeral: true })
|
||||
|
||||
@ -31,4 +32,4 @@ export default {
|
||||
console.log(error)
|
||||
}
|
||||
},
|
||||
};
|
||||
} as Command
|
@ -1,6 +1,6 @@
|
||||
import { CacheType, ChatInputCommandInteraction, Message, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import ConfigManager from '../controller/ConfigManager';
|
||||
import UserManager from '../controller/UserManager';
|
||||
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import UserController from '../controller/UserController';
|
||||
import { Command } from '.';
|
||||
|
||||
|
||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||
@ -10,13 +10,13 @@ export default {
|
||||
.setName('sync_users')
|
||||
.setDescription('Sync users')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
||||
const userManager = new UserManager(config)
|
||||
async execute(interaction) {
|
||||
const userController = new UserController()
|
||||
|
||||
await interaction.deferReply({ ephemeral: true })
|
||||
|
||||
try {
|
||||
const sync = await userManager.sync()
|
||||
const sync = await userController.sync()
|
||||
if (sync) {
|
||||
await interaction.followUp("Успешно")
|
||||
} else {
|
||||
@ -31,4 +31,4 @@ export default {
|
||||
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 ConfigManager from '../controller/ConfigManager';
|
||||
import ChatController from '../controller/ChatController';
|
||||
import { error } from 'console';
|
||||
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
import { Command } from '.';
|
||||
|
||||
// const adminPermissions = new PermissionsBitField('Administrator');
|
||||
|
||||
@ -10,7 +8,7 @@ export default {
|
||||
.setName('throw_chat_timestamp')
|
||||
.setDescription('throw chat timestamp')
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
async execute(interaction: ChatInputCommandInteraction<CacheType>, config: ConfigManager) {
|
||||
async execute(interaction) {
|
||||
|
||||
await interaction.deferReply({ ephemeral: true })
|
||||
|
||||
@ -24,4 +22,4 @@ export default {
|
||||
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 UserI from "../types/UserI";
|
||||
import MessageI from "../types/MessageI";
|
||||
import { channel } from "diagnostics_channel";
|
||||
|
||||
var isSyncing = false
|
||||
|
||||
@ -70,9 +66,12 @@ export default class ChatController {
|
||||
}
|
||||
|
||||
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)
|
||||
global.config.messageTime = m.Timestamp
|
||||
|
||||
// const me = new EmbedBuilder()
|
||||
// me.setDescription(m.Text)
|
||||
// me.setAuthor({ name: m.Sender })
|
||||
|
@ -2,29 +2,23 @@ import path from "path";
|
||||
import fs from "fs";
|
||||
import UserI from "../types/UserI";
|
||||
import { ServerInfoI } from "../types/ServerInfoI";
|
||||
import MessageI from "../types/MessageI";
|
||||
|
||||
interface ConfigManagerI {
|
||||
userManager?: {
|
||||
users: UserI[];
|
||||
authCodes: Date[];
|
||||
};
|
||||
messages?: MessageI[];
|
||||
interface ConfigControllerI {
|
||||
users: { name: string, value: UserI }[];
|
||||
usersInGame: UserI[];
|
||||
messageTime: number;
|
||||
inGameChat: string;
|
||||
serverInfo?: ServerInfoI;
|
||||
chatChannelId?: string;
|
||||
}
|
||||
|
||||
export default class ConfigManager {
|
||||
export default class ConfigController {
|
||||
configPath = path.join(process.env.STORAGE || "/app/storage", "config.json")
|
||||
public userManager: {
|
||||
users: UserI[];
|
||||
authCodes: Date[];
|
||||
} = {
|
||||
users: [],
|
||||
authCodes: [],
|
||||
}
|
||||
public usersInGame: UserI[] = [];
|
||||
public users: Map<string, UserI> = new Map<string, UserI>();
|
||||
public authCodes: Map<string, string> = new Map<string, string>();
|
||||
public chatChannelId: string = ""
|
||||
public inGameChat: string = "General"
|
||||
public messageTime: number = 0
|
||||
|
||||
constructor() {
|
||||
@ -32,27 +26,33 @@ export default class ConfigManager {
|
||||
setInterval(() => this.save(), 10000)
|
||||
}
|
||||
save() {
|
||||
const r: ConfigManagerI = {
|
||||
userManager: this.userManager,
|
||||
const r: ConfigControllerI = {
|
||||
users: Array.from(this.users, ([name, value]) => ({ name, value })),
|
||||
chatChannelId: this.chatChannelId,
|
||||
messageTime: this.messageTime,
|
||||
inGameChat: this.inGameChat,
|
||||
usersInGame: this.usersInGame,
|
||||
}
|
||||
fs.writeFileSync(this.configPath, JSON.stringify(r))
|
||||
}
|
||||
load() {
|
||||
const r = {
|
||||
userManager: this.userManager,
|
||||
chatChannelId: this.chatChannelId,
|
||||
users: this.users,
|
||||
messageTime: this.messageTime,
|
||||
}
|
||||
if (!fs.existsSync(this.configPath)) {
|
||||
fs.writeFileSync(this.configPath, JSON.stringify(r))
|
||||
}
|
||||
try {
|
||||
const t: ConfigManagerI = JSON.parse(String(fs.readFileSync(this.configPath)))
|
||||
if (!!t?.userManager)
|
||||
this.userManager = { ...this.userManager, ...t.userManager }
|
||||
const t: ConfigControllerI = JSON.parse(String(fs.readFileSync(this.configPath)))
|
||||
if (!!t?.users)
|
||||
this.users = new Map<string, UserI>(t.users.map(v => [v.name, v.value]))
|
||||
if (!!t?.usersInGame)
|
||||
this.usersInGame = t.usersInGame
|
||||
if (!!t?.messageTime)
|
||||
this.messageTime = t.messageTime
|
||||
if (!!t?.inGameChat)
|
||||
this.inGameChat = t.inGameChat
|
||||
if (!!t?.chatChannelId)
|
||||
this.chatChannelId = t.chatChannelId
|
||||
} 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 UserI from "../types/UserI";
|
||||
import CommandReplyI from "../types/CommandReplyI";
|
||||
import MessageReplyI from "../types/MessageReplyI";
|
||||
|
||||
export default class EcoManager {
|
||||
config: ConfigManager
|
||||
public constructor(config: ConfigManager) {
|
||||
this.config = config
|
||||
}
|
||||
export default class EcoController {
|
||||
public async Alert(message: string) {
|
||||
if (!message) return null
|
||||
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 UserI from "../types/UserI";
|
||||
|
||||
export default class UserManager {
|
||||
config: ConfigManager
|
||||
public constructor(config: ConfigManager) {
|
||||
this.config = config
|
||||
}
|
||||
export default class UserController {
|
||||
public async sync() {
|
||||
try {
|
||||
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
|
||||
|
||||
this.config.userManager.users = data
|
||||
global.config.usersInGame = data
|
||||
|
||||
return true
|
||||
} catch (error) {
|
77
src/index.ts
77
src/index.ts
@ -1,11 +1,12 @@
|
||||
import dotenv from 'dotenv';
|
||||
import { ActivityType, Client, Events, GatewayIntentBits, Partials } from 'discord.js'
|
||||
import axios from 'axios';
|
||||
import ConfigManager from './controller/ConfigManager';
|
||||
import ConfigController from './controller/ConfigController';
|
||||
import updateCommands from './updateCommands';
|
||||
import commands from './commands';
|
||||
import { ServerInfoI } from './types/ServerInfoI';
|
||||
import ChatController from './controller/ChatController';
|
||||
import UserController from './controller/UserController';
|
||||
|
||||
dotenv.config()
|
||||
|
||||
@ -25,11 +26,12 @@ const client = new Client({
|
||||
|
||||
declare global {
|
||||
var client: Client<boolean>;
|
||||
var config: ConfigManager;
|
||||
var config: ConfigController;
|
||||
}
|
||||
|
||||
const config = new ConfigManager()
|
||||
const config = new ConfigController()
|
||||
const chatController = new ChatController()
|
||||
const userController = new UserController()
|
||||
|
||||
global.client = client
|
||||
global.config = config
|
||||
@ -39,6 +41,7 @@ client.on('ready', () => {
|
||||
updateServerData();
|
||||
setInterval(updateServerData, 10000)
|
||||
setInterval(() => { chatController.syncMessageWithDiscord() }, 2000)
|
||||
setInterval(() => { userController.sync() }, 10000)
|
||||
});
|
||||
|
||||
async function updateServerData() {
|
||||
@ -63,7 +66,7 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||
try {
|
||||
if (interaction.isChatInputCommand()) {
|
||||
|
||||
const command: any = commands.get(interaction.commandName);
|
||||
const command = commands.get(interaction.commandName);
|
||||
|
||||
if (!command) {
|
||||
console.log(`No command matching ${interaction.commandName} was found.`);
|
||||
@ -71,7 +74,7 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||
}
|
||||
|
||||
try {
|
||||
await command.execute(interaction, config);
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
// console.log(`Error executing ${interaction.commandName}`);
|
||||
// console.log(error);
|
||||
@ -85,61 +88,31 @@ client.on(Events.InteractionCreate, async interaction => {
|
||||
|
||||
console.log(error)
|
||||
}
|
||||
} else
|
||||
return
|
||||
} 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
|
||||
} catch (error) {
|
||||
// console.log(error)
|
||||
console.log(error)
|
||||
}
|
||||
});
|
||||
|
||||
// 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);
|
||||
|
||||
updateCommands(config)
|
||||
updateCommands()
|
||||
if (!!process.env.DISCORD_TOKEN)
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
else
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { REST } from "@discordjs/rest";
|
||||
import { Routes } from "discord.js";
|
||||
import com from './commands'
|
||||
import ConfigManager from "./controller/ConfigManager";
|
||||
import { PermissionFlagsBits, Routes } from "discord.js";
|
||||
import com, { Command } from './commands'
|
||||
|
||||
export default function updateCommands(config: ConfigManager) {
|
||||
const commands: any = []
|
||||
export default function updateCommands() {
|
||||
const commands: Command[] = []
|
||||
const commandsGlobal: Command[] = []
|
||||
|
||||
if (!process.env.DISCORD_TOKEN)
|
||||
throw new Error("Token is null");
|
||||
|
||||
com.forEach((command: any) => {
|
||||
com.forEach((command) => {
|
||||
commands.push(command.data.toJSON() as never)
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user