mirror of
				https://github.com/keanuplayz/TravBot-v3.git
				synced 2024-08-15 02:33:12 +00:00 
			
		
		
		
	Added optional channel target for setting channel
This commit is contained in:
		
							parent
							
								
									3362f9fbbe
								
							
						
					
					
						commit
						678485160e
					
				
					 4 changed files with 37 additions and 12 deletions
				
			
		|  | @ -166,7 +166,8 @@ export default new Command({ | ||||||
|                     } |                     } | ||||||
|                 }), |                 }), | ||||||
|                 stream: new Command({ |                 stream: new Command({ | ||||||
|                     description: "Set a channel to send stream notifications.", |                     description: "Set a channel to send stream notifications. Type `#` to reference the channel.", | ||||||
|  |                     usage: "(<channel mention>)", | ||||||
|                     async run($) { |                     async run($) { | ||||||
|                         if ($.guild) { |                         if ($.guild) { | ||||||
|                             const guild = Storage.getGuild($.guild.id); |                             const guild = Storage.getGuild($.guild.id); | ||||||
|  | @ -183,7 +184,27 @@ export default new Command({ | ||||||
|                         } else { |                         } else { | ||||||
|                             $.channel.send("You must use this command in a server."); |                             $.channel.send("You must use this command in a server."); | ||||||
|                         } |                         } | ||||||
|  |                     }, | ||||||
|  |                     // If/when channel types come out, this will be the perfect candidate to test it.
 | ||||||
|  |                     any: new Command({ | ||||||
|  |                         async run($) { | ||||||
|  |                             if ($.guild) { | ||||||
|  |                                 const match = $.args[0].match(/^<#(\d{17,19})>$/); | ||||||
|  | 
 | ||||||
|  |                                 if (match) { | ||||||
|  |                                     Storage.getGuild($.guild.id).streamingChannel = match[1]; | ||||||
|  |                                     Storage.save(); | ||||||
|  |                                     $.channel.send(`Successfully set this server's welcome channel to ${match[0]}.`); | ||||||
|  |                                 } else { | ||||||
|  |                                     $.channel.send( | ||||||
|  |                                         "You must provide a reference channel. You can do this by typing `#` then searching for the proper channel." | ||||||
|  |                                     ); | ||||||
|                                 } |                                 } | ||||||
|  |                             } else { | ||||||
|  |                                 $.channel.send("You must use this command in a server."); | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                     }) | ||||||
|                 }) |                 }) | ||||||
|             } |             } | ||||||
|         }), |         }), | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| import Command from "../../core/command"; | import Command from "../../core/command"; | ||||||
| import {streamList, getStreamEmbed} from "../../events/voiceStateUpdate"; | import {streamList} from "../../events/voiceStateUpdate"; | ||||||
| 
 | 
 | ||||||
| export default new Command({ | export default new Command({ | ||||||
|     description: "Sets the description of your stream. You can embed links by writing `[some name](some link)`", |     description: "Sets the description of your stream. You can embed links by writing `[some name](some link)`", | ||||||
|  | @ -8,8 +8,8 @@ export default new Command({ | ||||||
| 
 | 
 | ||||||
|         if (streamList.has(userID)) { |         if (streamList.has(userID)) { | ||||||
|             const stream = streamList.get(userID)!; |             const stream = streamList.get(userID)!; | ||||||
|             stream.description = $.args.join(" ") || undefined; |             stream.description = $.args.join(" ") || "No description set."; | ||||||
|             stream.message.edit(getStreamEmbed(stream.streamer, stream.channel, stream.description)); |             stream.update(); | ||||||
|         } else { |         } else { | ||||||
|             // Alternatively, I could make descriptions last outside of just one stream.
 |             // Alternatively, I could make descriptions last outside of just one stream.
 | ||||||
|             $.channel.send("You can only use this command when streaming."); |             $.channel.send("You can only use this command when streaming."); | ||||||
|  |  | ||||||
|  | @ -1,12 +1,12 @@ | ||||||
| import Event from "../core/event"; | import Event from "../core/event"; | ||||||
| import {streamList, getStreamEmbed} from "./voiceStateUpdate"; | import {streamList} from "./voiceStateUpdate"; | ||||||
| 
 | 
 | ||||||
| export default new Event<"channelUpdate">({ | export default new Event<"channelUpdate">({ | ||||||
|     async on(before, after) { |     async on(before, after) { | ||||||
|         if (before.type === "voice" && after.type === "voice") { |         if (before.type === "voice" && after.type === "voice") { | ||||||
|             for (const {streamer, channel, description, message} of streamList.values()) { |             for (const stream of streamList.values()) { | ||||||
|                 if (after.id === channel.id) { |                 if (after.id === stream.channel.id) { | ||||||
|                     message.edit(getStreamEmbed(streamer, channel, description)); |                     stream.update(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -9,13 +9,14 @@ type Stream = { | ||||||
|     channel: VoiceChannel; |     channel: VoiceChannel; | ||||||
|     description?: string; |     description?: string; | ||||||
|     message: Message; |     message: Message; | ||||||
|  |     update: () => void; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| // A list of user IDs and message embeds.
 | // A list of user IDs and message embeds.
 | ||||||
| export const streamList = new Collection<string, Stream>(); | export const streamList = new Collection<string, Stream>(); | ||||||
| 
 | 
 | ||||||
| // Probably find a better, DRY way of doing this.
 | // Probably find a better, DRY way of doing this.
 | ||||||
| export function getStreamEmbed(streamer: GuildMember, channel: VoiceChannel, description?: string): MessageEmbed { | function getStreamEmbed(streamer: GuildMember, channel: VoiceChannel, description?: string): MessageEmbed { | ||||||
|     const user = streamer.user; |     const user = streamer.user; | ||||||
|     const embed = new MessageEmbed() |     const embed = new MessageEmbed() | ||||||
|         .setTitle(`Stream: \`#${channel.name}\``) |         .setTitle(`Stream: \`#${channel.name}\``) | ||||||
|  | @ -49,12 +50,15 @@ export default new Event<"voiceStateUpdate">({ | ||||||
|                 const voiceChannel = after.channel!; |                 const voiceChannel = after.channel!; | ||||||
|                 const textChannel = client.channels.cache.get(streamingChannel); |                 const textChannel = client.channels.cache.get(streamingChannel); | ||||||
| 
 | 
 | ||||||
|                 if (textChannel && textChannel instanceof TextChannel) { |                 if (textChannel instanceof TextChannel) { | ||||||
|                     if (isStartStreamEvent) { |                     if (isStartStreamEvent) { | ||||||
|                         streamList.set(member.id, { |                         streamList.set(member.id, { | ||||||
|                             streamer: member, |                             streamer: member, | ||||||
|                             channel: voiceChannel, |                             channel: voiceChannel, | ||||||
|                             message: await textChannel.send(getStreamEmbed(member, voiceChannel)) |                             message: await textChannel.send(getStreamEmbed(member, voiceChannel)), | ||||||
|  |                             update(this: Stream) { | ||||||
|  |                                 this.message.edit(getStreamEmbed(this.streamer, this.channel, this.description)); | ||||||
|  |                             } | ||||||
|                         }); |                         }); | ||||||
|                     } else if (isStopStreamEvent) { |                     } else if (isStopStreamEvent) { | ||||||
|                         if (streamList.has(member.id)) { |                         if (streamList.has(member.id)) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue