mirror of
https://github.com/DarthKilroy/Spot.git
synced 2025-12-19 02:06:48 +00:00
Fix spot
This commit is contained in:
parent
d4f2acaae6
commit
0ee296033c
5 changed files with 839 additions and 428 deletions
53
bot.ts
53
bot.ts
|
|
@ -1,48 +1,29 @@
|
|||
import { Client, GatewayIntentBits, GuildMember, Channel, TextBasedChannel, Events, Message, SlashCommandBuilder, Collection } from 'discord.js';
|
||||
import * as dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
import config from "./config";
|
||||
|
||||
import { Socket } from 'detritus-client-socket/lib/gateway';
|
||||
import { Client } from "detritus-client-rest";
|
||||
|
||||
import * as types from 'discord-api-types/v10';
|
||||
|
||||
const socket = new Socket(process.env.token!, { intents: 33283 });
|
||||
export const restClient = new Client(process.env.token);
|
||||
export const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
|
||||
|
||||
import handleMessage from './messageHandler';
|
||||
import help from './command/help';
|
||||
|
||||
socket.on('packet', async (evt: types.GatewayDispatchPayload) => handleEvtInner(evt).catch(e => console.error(e, JSON.stringify(e, null, 2))));
|
||||
client.on("ready", () => {
|
||||
console.log("successfully logged in");
|
||||
});
|
||||
|
||||
async function handleEvtInner(evt: types.GatewayDispatchPayload) {
|
||||
if (evt.op != 0) return;
|
||||
if (evt.t == 'READY') {
|
||||
console.log("successfully logged in:", evt.d.user);
|
||||
}
|
||||
client.on("guildMemberAdd", async (member: GuildMember) => {
|
||||
const msg = `Welcome, <@${member.id}>! If you joined for any specific support questions `
|
||||
+ `please check out <#863171642905591830> first to see if your issue is known, `
|
||||
+ `and make sure that your app is up-to-date before posting.`;
|
||||
|
||||
// i am quite sure this is the correct type
|
||||
// @ts-expect-error
|
||||
if (evt.t == 'INTERACTION_CREATE') await help.interactionHandler(evt.d);
|
||||
|
||||
if (evt.t == 'GUILD_MEMBER_ADD') {
|
||||
if (evt.d.guild_id != config.guild) return;
|
||||
if (evt.d.user!.bot) return;
|
||||
|
||||
const msg = `Welcome, <@${evt.d.user!.id}>! If you joined for any specific support questions `
|
||||
+ `please check out <#863171642905591830> first to see if your issue is known, `
|
||||
+ `and make sure that your app is up-to-date before posting.`;
|
||||
await restClient.createMessage(config.channels.joins, { content: msg });
|
||||
}
|
||||
|
||||
if (evt.t == 'MESSAGE_CREATE') {
|
||||
if (evt.d.guild_id != config.guild) return;
|
||||
if (evt.d.author.bot) return;
|
||||
await handleMessage(evt.d).catch(console.error);
|
||||
}
|
||||
};
|
||||
const channel: TextBasedChannel | null = await client.channels.fetch(config.channels.joins) as TextBasedChannel;
|
||||
channel?.send(msg);
|
||||
});
|
||||
|
||||
|
||||
console.log('Logging in...');
|
||||
socket.connect("https://gateway.discord.gg");
|
||||
client.on(Events.MessageCreate, async (msg: Message) => {
|
||||
await handleMessage(msg).catch(console.error);
|
||||
});
|
||||
|
||||
client.login(process.env.token);
|
||||
|
|
|
|||
|
|
@ -1,46 +1,25 @@
|
|||
import * as types from 'discord-api-types/v10';
|
||||
import CommandCategory from './model/command-category';
|
||||
import { restClient } from './bot';
|
||||
import { client } from './bot';
|
||||
import config from './config';
|
||||
|
||||
import avatar from './command/avatar';
|
||||
import changelog from './command/changelog';
|
||||
import clean from './command/clean';
|
||||
import eval from './command/eval';
|
||||
import help from './command/help';
|
||||
import ticket from './command/ticket';
|
||||
|
||||
import * as customMessages from './model/messages';
|
||||
|
||||
export interface Command {
|
||||
aliases: string[];
|
||||
category: CommandCategory;
|
||||
isAllowedForContext(_: types.GatewayMessageCreateDispatchData): boolean;
|
||||
description?: string;
|
||||
process(_: types.GatewayMessageCreateDispatchData, __: string[]): Promise<void>;
|
||||
}
|
||||
|
||||
const privCommands: Record<string, Command> = {};
|
||||
|
||||
export const commands = [avatar, changelog, clean, eval, help, ticket];
|
||||
import { Message, TextBasedChannel } from 'discord.js';
|
||||
|
||||
|
||||
commands.map((x: Command) => {
|
||||
x.aliases.map(a => privCommands[a] = x);
|
||||
});
|
||||
|
||||
export default async function handleMessage(message: types.GatewayMessageCreateDispatchData) {
|
||||
export default async function handleMessage(message: Message) {
|
||||
if (!message.content.toLowerCase().startsWith(config.prefix))
|
||||
return false;
|
||||
return false;
|
||||
|
||||
let args = message.content.substr(config.prefix.length).trim().split(' ');
|
||||
const calledCommand = args.shift()!.toLowerCase();
|
||||
|
||||
const embed = customMessages.getEmbed(calledCommand);
|
||||
if (embed != null)
|
||||
return await restClient.createMessage(message.channel_id, { embed });
|
||||
|
||||
const foundCommand = privCommands[calledCommand];
|
||||
if (foundCommand == null || !foundCommand.isAllowedForContext(message)) return;
|
||||
await foundCommand.process(message, args);
|
||||
if (embed != null) {
|
||||
const channel: TextBasedChannel | null = await client.channels.cache.get(message.channelId) as TextBasedChannel
|
||||
channel.send({
|
||||
embeds: [{
|
||||
color: embed.color,
|
||||
title: embed.author.name,
|
||||
description: embed.description
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { restClient } from "../bot";
|
||||
import { client } from "../bot";
|
||||
|
||||
interface Message {
|
||||
names: string[];
|
||||
|
|
@ -12,15 +12,17 @@ interface Message {
|
|||
export const messages: Record<string, Message> = {};
|
||||
let avatarUrl = "";
|
||||
|
||||
const load = async () =>
|
||||
{
|
||||
const load = async () => {
|
||||
const messagesList = require('../messages.json')["faq"];
|
||||
messagesList.forEach((msg: any) => {
|
||||
messages[msg["title"]] = msg
|
||||
})
|
||||
|
||||
const userInfo = await restClient.fetchMe();
|
||||
avatarUrl = `https://cdn.discordapp.com/avatars/${userInfo.id}/${userInfo.avatar}.png`;
|
||||
const userInfo = await client.user;
|
||||
|
||||
const avatar = userInfo?.avatarURL() ?? '';
|
||||
|
||||
avatarUrl = avatar;
|
||||
console.log(avatarUrl);
|
||||
}
|
||||
|
||||
|
|
@ -32,14 +34,12 @@ export const getList = () => Object.keys(messages).map(msg => ({ name: messages[
|
|||
|
||||
export const getEmbed = (name: string) => {
|
||||
let foundMsg: Message | undefined;
|
||||
Object.keys(messages).forEach((msgKey) =>
|
||||
{
|
||||
Object.keys(messages).forEach((msgKey) => {
|
||||
if (foundMsg) return;
|
||||
|
||||
const msg = messages[msgKey]
|
||||
|
||||
if (msg.names.includes(name))
|
||||
{
|
||||
if (msg.names.includes(name)) {
|
||||
foundMsg = msg;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
1138
package-lock.json
generated
1138
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,17 +5,18 @@
|
|||
"main": "bot.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "ts-node bot.ts"
|
||||
"start": "ts-node bot.ts",
|
||||
"start:watch": "ts-node-dev --respawn --cache-directory ./tmp -- ./bot.ts"
|
||||
},
|
||||
"author": "Lily Wonhalf <lilywonhalf@gmail.com>",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.1.3",
|
||||
"detritus-client-rest": "git+https://github.com/spiralw/DiscordRest#fix-build",
|
||||
"detritus-client-socket": "git+https://github.com/spiralw/DiscordSocket#fix-build",
|
||||
"discord-api-types": "^0.37.14",
|
||||
"discord.js": "^14.14.1",
|
||||
"dotenv": "^16.0.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"ts-node-dev": "^2.0.0",
|
||||
"typescript": "^4.8.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue