Skip to content

Commit

Permalink
Update .env.example, .gitignore, NodeConnect.ts, and Lavamusic.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Mar 13, 2024
1 parent 6c8c575 commit efcfad7
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 5 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ OWNER_IDS=["959276033683628122","859640640640640640"] # Your discord id, you can

GUILD_ID= "859640640640640640" # Your server Id if you want to use the for single server

CLIENT_SECRET= ""

PRODUCTION="true" # true for production

SEARCH_ENGINE= "ytsearch" # ytsearch, scsearch or ytmsearch
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@
/Lavalink/application.yml

/Lavalink/plugins

lavamusic.db
lavamusic.db-shm
lavamusic.db-wal
2 changes: 2 additions & 0 deletions src/events/player/NodeConnect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Event, Lavamusic } from '../../structures/index.js';
import BotLog from '../../utils/BotLog.js';

export default class NodeConnect extends Event {
constructor(client: Lavamusic, file: string) {
Expand All @@ -22,5 +23,6 @@ export default class NodeConnect extends Event {
await this.client.queue.create(guild, vc, channel);
}, index * 1000);
}
BotLog.send(this.client, `Node ${node} is ready!`, 'success');
}
}
14 changes: 14 additions & 0 deletions src/events/player/NodeDestroy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Event, Lavamusic } from '../../structures/index.js';
import BotLog from '../../utils/BotLog.js';

export default class NodeDestroy extends Event {
constructor(client: Lavamusic, file: string) {
super(client, file, {
name: 'nodeDestroy',
});
}
public async run(node: string, code: number, reason: string): Promise<void> {
this.client.logger.error(`Node ${node} destroyed with code ${code} and reason ${reason}`);
BotLog.send(this.client, `Node ${node} destroyed with code ${code} and reason ${reason}`, 'error')
}
}
14 changes: 14 additions & 0 deletions src/events/player/NodeDisconnect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Event, Lavamusic } from '../../structures/index.js';
import BotLog from '../../utils/BotLog.js';

export default class NodeDisconnect extends Event {
constructor(client: Lavamusic, file: string) {
super(client, file, {
name: 'nodeDisconnect',
});
}
public async run(node: string, count: number): Promise<void> {
this.client.logger.warn(`Node ${node} disconnected ${count} times`);
BotLog.send(this.client, `Node ${node} disconnected ${count} times`, 'warn')
}
}
14 changes: 14 additions & 0 deletions src/events/player/NodeError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Event, Lavamusic } from '../../structures/index.js';
import BotLog from '../../utils/BotLog.js';

export default class NodeError extends Event {
constructor(client: Lavamusic, file: string) {
super(client, file, {
name: 'nodeError',
});
}
public async run(node: string, error: any): Promise<void> {
this.client.logger.error(`Node ${node} Error: ${JSON.stringify(error)}`);
BotLog.send(this.client, `Node ${node} Error: ${JSON.stringify(error)}`, 'error')
}
}
13 changes: 13 additions & 0 deletions src/events/player/NodeRaw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Event, Lavamusic } from '../../structures/index.js';


export default class NodeRaw extends Event {
constructor(client: Lavamusic, file: string) {
super(client, file, {
name: 'nodeRaw',
});
}
public async run(payload: any): Promise<void> {
//this.client.logger.debug(`Node raw event: ${JSON.stringify(payload)}`);
}
}
14 changes: 14 additions & 0 deletions src/events/player/NodeReconnect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Event, Lavamusic } from '../../structures/index.js';
import BotLog from '../../utils/BotLog.js';

export default class NodeReconnect extends Event {
constructor(client: Lavamusic, file: string) {
super(client, file, {
name: 'nodeReconnect',
});
}
public async run(node: string): Promise<void> {
this.client.logger.warn(`Node ${node} reconnected`);
BotLog.send(this.client, `Node ${node} reconnected`, 'warn')
}
}
6 changes: 3 additions & 3 deletions src/structures/Lavamusic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export default class Lavamusic extends Client {
this.config.production === true
? Routes.applicationCommands(this.user.id ?? '')
: Routes.applicationGuildCommands(
this.user.id ?? '',
this.config.guildId ?? ''
);
this.user.id ?? '',
this.config.guildId ?? ''
);
try {
const rest = new REST({ version: '9' }).setToken(this.config.token ?? '');
await rest.put(applicationCommands, { body: this.body });
Expand Down
37 changes: 37 additions & 0 deletions src/utils/BotLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { TextChannel } from 'discord.js';
import { Lavamusic } from '../structures/index.js';


export default class BotLog {
public static send(client: Lavamusic, message: string, type: string): void {
if (!client) return;
if (!client.channels.cache) return;
if (!client.config.logChannelId) return;
const channel = client.channels.cache.get(client.config.logChannelId) as TextChannel;
if (!channel) return;
let color: string | number | readonly [red: number, green: number, blue: number];
switch (type) {
case 'error':
color = 0xff0000;
break;
case 'warn':
color = 0xffff00;
break;
case 'info':
color = 0x00ff00;
break;
case 'success':
color = 0x00ff00;
break;
default:
color = 0x000000;
break;
}
const embed = client.embed()
.setColor(color)
.setDescription(message)
.setTimestamp();

channel.send({ embeds: [embed] }).catch(() => {null});
}
}

0 comments on commit efcfad7

Please sign in to comment.