mirror of
				https://github.com/keanuplayz/TravBot-v3.git
				synced 2024-08-15 02:33:12 +00:00 
			
		
		
		
	Small fixes and rework of poll
This commit is contained in:
		
							parent
							
								
									8142709581
								
							
						
					
					
						commit
						6ea052ae6f
					
				
					 4 changed files with 68 additions and 34 deletions
				
			
		|  | @ -1,4 +1,4 @@ | ||||||
| import {Command, NamedCommand} from "../../core"; | import {NamedCommand, RestCommand} from "../../core"; | ||||||
| import {random} from "../../lib"; | import {random} from "../../lib"; | ||||||
| 
 | 
 | ||||||
| const responses = [ | const responses = [ | ||||||
|  | @ -28,11 +28,10 @@ export default new NamedCommand({ | ||||||
|     description: "Answers your question in an 8-ball manner.", |     description: "Answers your question in an 8-ball manner.", | ||||||
|     usage: "<question>", |     usage: "<question>", | ||||||
|     run: "Please provide a question.", |     run: "Please provide a question.", | ||||||
|     any: new Command({ |     any: new RestCommand({ | ||||||
|         description: "Question to ask the 8-ball.", |         description: "Question to ask the 8-ball.", | ||||||
|         async run({send, message}) { |         async run({send, author}) { | ||||||
|             const sender = message.author; |             send(`${random(responses)} ${author}`); | ||||||
|             send(`${random(responses)} <@${sender.id}>`); |  | ||||||
|         } |         } | ||||||
|     }) |     }) | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -40,13 +40,12 @@ export default new NamedCommand({ | ||||||
|     user: new Command({ |     user: new Command({ | ||||||
|         description: "User to give cookie to.", |         description: "User to give cookie to.", | ||||||
|         async run({send, author, args}) { |         async run({send, author, args}) { | ||||||
|             const sender = author; |  | ||||||
|             const mention: User = args[0]; |             const mention: User = args[0]; | ||||||
| 
 | 
 | ||||||
|             if (mention.id == sender.id) return send("You can't give yourself cookies!"); |             if (mention.id == author.id) return send("You can't give yourself cookies!"); | ||||||
| 
 | 
 | ||||||
|             return send( |             return send( | ||||||
|                 `:cookie: <@${sender.id}> ${parseVars(random(cookies), { |                 `:cookie: ${author} ${parseVars(random(cookies), { | ||||||
|                     target: mention.toString() |                     target: mention.toString() | ||||||
|                 })}` |                 })}` | ||||||
|             ); |             ); | ||||||
|  |  | ||||||
|  | @ -1,27 +1,58 @@ | ||||||
| import {MessageEmbed} from "discord.js"; | import {MessageEmbed, Message, User} from "discord.js"; | ||||||
| import {NamedCommand, RestCommand} from "../../core"; | import {NamedCommand, RestCommand, poll, CHANNEL_TYPE, SendFunction, Command} from "../../core"; | ||||||
|  | import {pluralise} from "../../lib"; | ||||||
| 
 | 
 | ||||||
| export default new NamedCommand({ | export default new NamedCommand({ | ||||||
|     description: "Create a poll.", |     description: "Create a poll.", | ||||||
|     usage: "<question>", |     usage: "(<seconds>) <question>", | ||||||
|     run: "Please provide a question.", |     run: "Please provide a question.", | ||||||
|  |     channelType: CHANNEL_TYPE.GUILD, | ||||||
|  |     number: new Command({ | ||||||
|  |         run: "Please provide a question in addition to the provided duration.", | ||||||
|         any: new RestCommand({ |         any: new RestCommand({ | ||||||
|             description: "Question for the poll.", |             description: "Question for the poll.", | ||||||
|         async run({send, message, combined}) { |             async run({send, message, author, args, combined}) { | ||||||
|             const embed = new MessageEmbed() |                 execPoll(send, message, author, combined, args[0]); | ||||||
|                 .setAuthor( |             } | ||||||
|                     `Poll created by ${message.author.username}`, |         }) | ||||||
|                     message.guild?.iconURL({dynamic: true}) ?? undefined |     }), | ||||||
|                 ) |     any: new RestCommand({ | ||||||
|                 .setColor(0xffffff) |         description: "Question for the poll.", | ||||||
|                 .setFooter("React to vote.") |         async run({send, message, author, combined}) { | ||||||
|                 .setDescription(combined); |             execPoll(send, message, author, combined); | ||||||
|             const msg = await send(embed); |  | ||||||
|             await msg.react("✅"); |  | ||||||
|             await msg.react("⛔"); |  | ||||||
|             message.delete({ |  | ||||||
|                 timeout: 1000 |  | ||||||
|             }); |  | ||||||
|         } |         } | ||||||
|     }) |     }) | ||||||
| }); | }); | ||||||
|  | 
 | ||||||
|  | const AGREE = "✅"; | ||||||
|  | const DISAGREE = "⛔"; | ||||||
|  | 
 | ||||||
|  | async function execPoll(send: SendFunction, message: Message, user: User, question: string, duration = 60000) { | ||||||
|  |     const icon = | ||||||
|  |         user.avatarURL({ | ||||||
|  |             dynamic: true, | ||||||
|  |             size: 2048 | ||||||
|  |         }) || user.defaultAvatarURL; | ||||||
|  |     const msg = await send( | ||||||
|  |         new MessageEmbed() | ||||||
|  |             .setAuthor(`Poll created by ${message.author.username}`, icon) | ||||||
|  |             .setColor(0xffffff) | ||||||
|  |             .setFooter("React to vote.") | ||||||
|  |             .setDescription(question) | ||||||
|  |     ); | ||||||
|  |     const results = await poll(msg, [AGREE, DISAGREE], duration); | ||||||
|  |     send( | ||||||
|  |         new MessageEmbed() | ||||||
|  |             .setAuthor(`The results of ${message.author.username}'s poll:`, icon) | ||||||
|  |             .setTitle(question) | ||||||
|  |             .setDescription( | ||||||
|  |                 `${AGREE} - ${pluralise( | ||||||
|  |                     results[AGREE], | ||||||
|  |                     "", | ||||||
|  |                     "people who agree", | ||||||
|  |                     "person who agrees" | ||||||
|  |                 )}\n${DISAGREE} - ${pluralise(results[DISAGREE], "", "people who disagree", "person who disagrees")}` | ||||||
|  |             ) | ||||||
|  |     ); | ||||||
|  |     msg.delete(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -1,12 +1,17 @@ | ||||||
| import {NamedCommand} from "../../core"; | import {Command, NamedCommand} from "../../core"; | ||||||
| 
 | 
 | ||||||
| export default new NamedCommand({ | export default new NamedCommand({ | ||||||
|     description: "Gives you the invite link.", |     description: "Gives you the invite link.", | ||||||
|  |     async run({send, client}) { | ||||||
|  |         send(`https://discordapp.com/api/oauth2/authorize?client_id=${client.user!.id}&permissions=8&scope=bot`); | ||||||
|  |     }, | ||||||
|  |     number: new Command({ | ||||||
|         async run({send, client, args}) { |         async run({send, client, args}) { | ||||||
|             send( |             send( | ||||||
|                 `https://discordapp.com/api/oauth2/authorize?client_id=${client.user!.id}&permissions=${ |                 `https://discordapp.com/api/oauth2/authorize?client_id=${client.user!.id}&permissions=${ | ||||||
|                 args[0] || 8 |                     args[0] | ||||||
|                 }&scope=bot` |                 }&scope=bot` | ||||||
|             ); |             ); | ||||||
|         } |         } | ||||||
|  |     }) | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue