export SlashModule
This commit is contained in:
		
							parent
							
								
									3dcf57c658
								
							
						
					
					
						commit
						844a408c74
					
				
					 6 changed files with 147 additions and 5 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -113,3 +113,5 @@ src/test/config.ts | ||||||
| 
 | 
 | ||||||
| # macOS is shit xD | # macOS is shit xD | ||||||
| **/.DS_Store | **/.DS_Store | ||||||
|  | 
 | ||||||
|  | src/test/music.mp3 | ||||||
							
								
								
									
										1
									
								
								mod.ts
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								mod.ts
									
										
									
									
									
								
							|  | @ -20,6 +20,7 @@ export { | ||||||
|   ExtensionCommands, |   ExtensionCommands, | ||||||
|   ExtensionsManager |   ExtensionsManager | ||||||
| } from './src/models/extensions.ts' | } from './src/models/extensions.ts' | ||||||
|  | export { SlashModule } from './src/models/slashModule.ts' | ||||||
| export { CommandClient, command } from './src/models/commandClient.ts' | export { CommandClient, command } from './src/models/commandClient.ts' | ||||||
| export type { CommandClientOptions } from './src/models/commandClient.ts' | export type { CommandClientOptions } from './src/models/commandClient.ts' | ||||||
| export { BaseManager } from './src/managers/base.ts' | export { BaseManager } from './src/managers/base.ts' | ||||||
|  |  | ||||||
|  | @ -15,6 +15,8 @@ export class VoiceState extends Base { | ||||||
|   sessionID: string |   sessionID: string | ||||||
|   deaf: boolean |   deaf: boolean | ||||||
|   mute: boolean |   mute: boolean | ||||||
|  |   selfDeaf: boolean | ||||||
|  |   selfMute: boolean | ||||||
|   stream?: boolean |   stream?: boolean | ||||||
|   video: boolean |   video: boolean | ||||||
|   suppress: boolean |   suppress: boolean | ||||||
|  | @ -38,8 +40,8 @@ export class VoiceState extends Base { | ||||||
|     this.guild = _data.guild |     this.guild = _data.guild | ||||||
|     this.deaf = data.deaf |     this.deaf = data.deaf | ||||||
|     this.mute = data.mute |     this.mute = data.mute | ||||||
|     this.deaf = data.self_deaf |     this.selfDeaf = data.self_deaf | ||||||
|     this.mute = data.self_mute |     this.selfMute = data.self_mute | ||||||
|     this.stream = data.self_stream |     this.stream = data.self_stream | ||||||
|     this.video = data.self_video |     this.video = data.self_video | ||||||
|     this.suppress = data.suppress |     this.suppress = data.suppress | ||||||
|  | @ -52,6 +54,8 @@ export class VoiceState extends Base { | ||||||
|     this.mute = data.mute ?? this.mute |     this.mute = data.mute ?? this.mute | ||||||
|     this.deaf = data.self_deaf ?? this.deaf |     this.deaf = data.self_deaf ?? this.deaf | ||||||
|     this.mute = data.self_mute ?? this.mute |     this.mute = data.self_mute ?? this.mute | ||||||
|  |     this.selfDeaf = data.self_deaf ?? this.selfDeaf | ||||||
|  |     this.selfMute = data.self_mute ?? this.selfMute | ||||||
|     this.stream = data.self_stream ?? this.stream |     this.stream = data.self_stream ?? this.stream | ||||||
|     this.video = data.self_video ?? this.video |     this.video = data.self_video ?? this.video | ||||||
|     this.suppress = data.suppress ?? this.suppress |     this.suppress = data.suppress ?? this.suppress | ||||||
|  |  | ||||||
							
								
								
									
										137
									
								
								src/test/music.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								src/test/music.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,137 @@ | ||||||
|  | import { | ||||||
|  |   CommandClient, | ||||||
|  |   event, | ||||||
|  |   Intents, | ||||||
|  |   command, | ||||||
|  |   CommandContext, | ||||||
|  |   Extension, | ||||||
|  |   Collection | ||||||
|  | } from '../../mod.ts' | ||||||
|  | import { LL_IP, LL_PASS, LL_PORT, TOKEN } from './config.ts' | ||||||
|  | import { | ||||||
|  |   Manager, | ||||||
|  |   Player | ||||||
|  | } from 'https://raw.githubusercontent.com/DjDeveloperr/lavaclient-deno/master/mod.ts' | ||||||
|  | 
 | ||||||
|  | export const nodes = [ | ||||||
|  |   { | ||||||
|  |     id: 'main', | ||||||
|  |     host: LL_IP, | ||||||
|  |     port: LL_PORT, | ||||||
|  |     password: LL_PASS | ||||||
|  |   } | ||||||
|  | ] | ||||||
|  | 
 | ||||||
|  | class MyClient extends CommandClient { | ||||||
|  |   manager: Manager | ||||||
|  | 
 | ||||||
|  |   constructor() { | ||||||
|  |     super({ | ||||||
|  |       prefix: ['.'], | ||||||
|  |       caseSensitive: false | ||||||
|  |     }) | ||||||
|  | 
 | ||||||
|  |     // eslint-disable-next-line @typescript-eslint/no-this-alias
 | ||||||
|  |     const client = this | ||||||
|  | 
 | ||||||
|  |     this.manager = new Manager(nodes, { | ||||||
|  |       send(id, payload) { | ||||||
|  |         // Sharding not added yet
 | ||||||
|  |         client.gateway?.send(payload) | ||||||
|  |       } | ||||||
|  |     }) | ||||||
|  | 
 | ||||||
|  |     this.manager.on('socketError', ({ id }, error) => | ||||||
|  |       console.error(`${id} ran into an error`, error) | ||||||
|  |     ) | ||||||
|  |     this.manager.on('socketReady', (node) => | ||||||
|  |       console.log(`${node.id} connected.`) | ||||||
|  |     ) | ||||||
|  | 
 | ||||||
|  |     this.on('raw', (evt: string, d: any) => { | ||||||
|  |       if (evt === 'VOICE_SERVER_UPDATE') this.manager.serverUpdate(d) | ||||||
|  |       else if (evt === 'VOICE_STATE_UPDATE') this.manager.stateUpdate(d) | ||||||
|  |     }) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @event() | ||||||
|  |   ready(): void { | ||||||
|  |     console.log(`Logged in as ${this.user?.tag}!`) | ||||||
|  |     this.manager.init(this.user?.id as string) | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const players = new Collection<string, Player>() | ||||||
|  | 
 | ||||||
|  | class VCExtension extends Extension { | ||||||
|  |   name = 'VC' | ||||||
|  |   subPrefix = 'vc' | ||||||
|  | 
 | ||||||
|  |   @command() | ||||||
|  |   async join(ctx: CommandContext): Promise<any> { | ||||||
|  |     if (players.has(ctx.guild?.id as string) === true) | ||||||
|  |       return ctx.message.reply(`Already playing in this server!`) | ||||||
|  | 
 | ||||||
|  |     ctx.argString = ctx.argString.slice(4).trim() | ||||||
|  | 
 | ||||||
|  |     if (ctx.argString === '') | ||||||
|  |       return ctx.message.reply('You gave nothing to search.') | ||||||
|  | 
 | ||||||
|  |     const userVS = await ctx.guild?.voiceStates.get(ctx.author.id) | ||||||
|  |     if (userVS === undefined) { | ||||||
|  |       ctx.message.reply("You're not in VC.") | ||||||
|  |       return | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const player = (ctx.client as MyClient).manager.create( | ||||||
|  |       ctx.guild?.id as string | ||||||
|  |     ) | ||||||
|  | 
 | ||||||
|  |     await player.connect(userVS.channel?.id as string, { selfDeaf: true }) | ||||||
|  | 
 | ||||||
|  |     ctx.message.reply(`Joined VC channel - ${userVS.channel?.name}!`) | ||||||
|  | 
 | ||||||
|  |     players.set(ctx.guild?.id as string, player) | ||||||
|  | 
 | ||||||
|  |     ctx.channel.send(`Loading...`) | ||||||
|  | 
 | ||||||
|  |     ctx.channel.send(`Searching for ${ctx.argString}...`) | ||||||
|  | 
 | ||||||
|  |     const { track, info } = await player.manager | ||||||
|  |       .search(`ytsearch:${ctx.argString}`) | ||||||
|  |       .then((e) => e.tracks[0]) | ||||||
|  | 
 | ||||||
|  |     await player.play(track) | ||||||
|  | 
 | ||||||
|  |     ctx.channel.send(`Now playing ${info.title}!`) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @command() | ||||||
|  |   async leave(ctx: CommandContext): Promise<any> { | ||||||
|  |     const userVS = await ctx.guild?.voiceStates.get( | ||||||
|  |       (ctx.client.user?.id as unknown) as string | ||||||
|  |     ) | ||||||
|  |     if (userVS === undefined) { | ||||||
|  |       ctx.message.reply("I'm not in VC.") | ||||||
|  |       return | ||||||
|  |     } | ||||||
|  |     userVS.channel?.leave() | ||||||
|  |     ctx.message.reply(`Left VC channel - ${userVS.channel?.name}!`) | ||||||
|  | 
 | ||||||
|  |     if (players.has(ctx.guild?.id as string) !== true) | ||||||
|  |       return ctx.message.reply('Not playing anything in this server.') | ||||||
|  | 
 | ||||||
|  |     const player = (players.get(ctx.guild?.id as string) as unknown) as Player | ||||||
|  |     await player.stop() | ||||||
|  |     await player.destroy() | ||||||
|  | 
 | ||||||
|  |     players.delete(ctx.guild?.id as string) | ||||||
|  |     ctx.message.reply('Stopped player') | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const client = new MyClient() | ||||||
|  | 
 | ||||||
|  | client.extensions.load(VCExtension) | ||||||
|  | 
 | ||||||
|  | client.connect(TOKEN, Intents.None) | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| export const UserFlags = { | export const UserFlags = { | ||||||
|   DISCORD_EMPLOYEE: 1 << 0, |   DISCORD_EMPLOYEE: 1 << 0, | ||||||
|   PARTNERED_SERVER_OWNER: 1 << 1, |   PARTNERED_SERVER_OWNER: 1 << 1, | ||||||
|   DISCORD_PARTNER: 1 << 1, |  | ||||||
|   HYPESQUAD_EVENTS: 1 << 2, |   HYPESQUAD_EVENTS: 1 << 2, | ||||||
|   BUGHUNTER_LEVEL_1: 1 << 3, |   BUGHUNTER_LEVEL_1: 1 << 3, | ||||||
|   HOUSE_BRAVERY: 1 << 6, |   HOUSE_BRAVERY: 1 << 6, | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| // https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice
 |  | ||||||
| import { MemberPayload } from './guild.ts' | import { MemberPayload } from './guild.ts' | ||||||
| 
 | 
 | ||||||
| export enum VoiceOpcodes { // add VoiceOpcodes - UnderC -
 | export enum VoiceOpcodes { | ||||||
|   IDENTIFY = 0, |   IDENTIFY = 0, | ||||||
|   SELECT_PROTOCOL = 1, |   SELECT_PROTOCOL = 1, | ||||||
|   READY = 2, |   READY = 2, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue