/[sudobot]/trunk/commands/send.js
ViewVC logotype

Contents of /trunk/commands/send.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (show annotations)
Mon Jul 29 17:28:21 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 2285 byte(s)
Release version 1.10.0

* Added -queues command to list all queued jobs
* Added -joke command to fetch random jokes
* Added support of user tags in some user-based commands
1 const { emoji } = require('../src/emoji');
2 const MessageEmbed = require('../src/MessageEmbed');
3 const { getUser } = require('../src/UserInput');
4
5 module.exports = {
6 async handle(msg, cm) {
7 if (cm.args[0] === undefined) {
8 await msg.reply({
9 embeds: [
10 new MessageEmbed()
11 .setColor('#f14a60')
12 .setDescription('This command requires at least 2 arguments')
13 ]
14 });
15
16 return;
17 }
18
19 try {
20 var user = await getUser(cm.args[0], msg);
21
22 console.log(user);
23
24 if (!user) {
25 throw new Error('Invalid User');
26 }
27 }
28 catch (e) {
29 console.log(e);
30
31 await msg.reply({
32 embeds: [
33 new MessageEmbed()
34 .setColor('#f14a60')
35 .setDescription(`Invalid user given.`)
36 ]
37 });
38
39 return;
40 }
41
42 const args = [...cm.args];
43 args.shift();
44
45 if (msg.attachments.size < 1 && args.length < 1) {
46 await msg.reply({
47 embeds: [
48 new MessageEmbed()
49 .setColor('#f14a60')
50 .setDescription('This command requires at least 2 arguments')
51 ]
52 });
53
54 return;
55 }
56
57 const content = args.join(' ');
58
59 try {
60 let message = {};
61
62 if (content.trim() != '') {
63 message.content = content;
64 }
65
66 if (msg.attachments && msg.attachments.size > 0) {
67 message.files = msg.attachments.map(a => {
68 return {
69 attachment: a.proxyURL,
70 name: a.name
71 }
72 });
73 }
74
75 await user.send(message);
76
77 await msg.reply({
78 content: (await emoji('check'))?.toString() + " Message Sent!"
79 });
80 }
81 catch(e) {
82 console.log(e);
83
84 await msg.reply({
85 content: "Message could not be sent, maybe the user has disabled DMs?"
86 });
87 }
88 }
89 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26