Browse Source

Role restore and quotes added

Robert 3 months ago
parent
commit
2cac27f456
2 changed files with 100 additions and 63 deletions
  1. 0
    0
      New Text Document.txt
  2. 100
    63
      commands.js

+ 0
- 0
New Text Document.txt View File


+ 100
- 63
commands.js View File

@@ -3,29 +3,30 @@ const debug = require('debug')('Bot:commands');
3 3
 const cmd = new Map();
4 4
 
5 5
 async function register(bot, args, message) {
6
-    let user = await db.getUser(message.guild.id, String(message.member.id));
7
-    if (user && user.roleID) {
8
-        message.channel.send(`${message.member} ばか~~、 Posiadasz juz role <@&${user.roleID}>!`);
9
-        return `User(${message.member.displayName}) already created role!`;
10
-    }
11
-    let role = await message.guild.roles.create({
12
-        data: {
13
-          name: '%'+message.member.displayName,
14
-          color: 'RANDOM',
15
-          position: 0
16
-        },
17
-        reason: 'Register command used.'
18
-      });
19
-    if(role && role.id) {
20
-        try {
21
-            message.member.roles.add(role);
22
-        } catch(err) { debug(err); throw err}
23
-        message.channel.send(`${message.author}, Your private role is ${role}`);
24
-        db.addUser(message.guild.id, String(message.member.id), String(role.id));
25
-    } else {message.channel.send(`${message.author}, Cos poszlo nie tak xD`);}
26
-    
6
+  let user = await db.getUser(message.guild.id, String(message.member.id));
7
+  if (user && user.roleID) {
8
+    message.channel.send(`${message.member} ばか~~、 Posiadasz juz role <@&${user.roleID}>!`);
9
+    return `User(${message.member.displayName}) already created role!`;
10
+  }
11
+  let position = message.guild.roles.resolve('496605731416571925').position + 1
12
+  let role = await message.guild.roles.create({
13
+    data: {
14
+      name: '%'+message.member.displayName,
15
+      color: 'RANDOM',
16
+      position: position
17
+    },
18
+    reason: 'Register command used.'
19
+  });
20
+  if(role && role.id) {
21
+    try {
22
+        message.member.roles.add(role);
23
+    } catch(err) { debug(err); throw err}
24
+    message.channel.send(`${message.author}, Your private role is ${role}`);
25
+    db.addUser(message.guild.id, String(message.member.id), String(role.id));
26
+  } else {message.channel.send(`${message.author}, Cos poszlo nie tak xD`);}
27 27
 }
28 28
 cmd.set('register', register);
29
+
29 30
 async function role(bot, args, message) {
30 31
     if (!args[0]) { return message.reply(`Usage of ...`); }
31 32
     const nestedCommands = {
@@ -34,57 +35,93 @@ async function role(bot, args, message) {
34 35
       restore: restore,
35 36
     };
36 37
     if (!{}.hasOwnProperty.call(nestedCommands, args[0])) { return message.reply(`Usage of ...`); }
38
+
39
+    const user = await db.getUser(message.guild.id, String(message.member.id));
40
+
41
+    if (!user) {
42
+      message.reply('You don\'t have private role! Type: /register');
43
+      throw new Error(`${message.member.displayName}, don't have private role!`);
44
+    }
45
+
46
+    const role = await message.guild.roles.resolve(user.roleID);
47
+
37 48
     nestedCommands[args[0]](bot, args, message);
38 49
 
39 50
     async function name(bot, args, message) {
40
-        const user = await db.getUser(message.guild.id, String(message.member.id));
41
-        if (!user) {
42
-            message.reply('You don\'t have private role!');
43
-            throw new Error(`${message.member.displayName}, don't have private role!`);
44
-        }
45
-        const role = await message.guild.roles.resolve(user.roleID);
46
-        const nestedCommands = {
47
-          get() {
48
-            return message.reply(`role name is ${role}.`);
49
-          },
50
-          set() {
51
-            const newName = args.slice(2, args.length).join(' ');
52
-            if (newName.length < 5) {
53
-              return message.reply('new role name is too short!');
54
-            }
55
-            role.setName("%" + newName)
56
-              .then(() => {
57
-                message.reply(`role name updated. ${role}`);
58
-              })
59
-              .catch(err => debug(err));
60
-          },
61
-        };
62
-        if (!{}.hasOwnProperty.call(nestedCommands, args[1])) { return message.reply(`Usage of ...`); }
63
-        nestedCommands[args[1]](message, args);
51
+      const nestedCommands = {
52
+        get() {
53
+          return message.reply(`role name is ${role}.`);
54
+        },
55
+        set() {
56
+          const newName = args.slice(2, args.length).join(' ');
57
+          if (newName.length < 5) {
58
+            return message.reply('new role name is too short!');
59
+          }
60
+          role.setName("%" + newName)
61
+            .then(() => {
62
+              message.reply(`role name updated. ${role}`);
63
+            })
64
+            .catch(err => debug(err));
65
+        },
66
+      };
67
+      if (!{}.hasOwnProperty.call(nestedCommands, args[1])) { return message.reply(`Usage of ...`); }
68
+      nestedCommands[args[1]](message, args);
64 69
     }
65 70
     async function color(bot, args, message) {
66
-        const user = await db.getUser(message.guild.id, String(message.member.id));
67
-        if (!user) {
68
-            message.reply('You don\'t have private role!');
69
-            throw new Error(`${message.member.displayName}, don't have private role!`);
71
+      const nestedCommands = {
72
+        get() {
73
+          return message.reply(`role color is ${role.hexColor}.`);
74
+        },
75
+        set() {
76
+          args[2] = args[2].toUpperCase();
77
+          message.guild.roles.resolve(user.roleID).setColor(args[2], 'Color change!');
78
+          message.reply(`Your new role color ${role}(${args[2]})`);
70 79
         }
71
-        const role = await message.guild.roles.resolve(user.roleID);
72
-        const nestedCommands = {
73
-          get() {
74
-            return message.reply(`role color is ${role.hexColor}.`);
75
-          },
76
-          set() {
77
-            args[2] = args[2].toUpperCase();
78
-            message.guild.roles.resolve(user.roleID).setColor(args[2], 'Color change!');
79
-            message.reply(`Your new role color ${role}(${args[2]})`);
80
-          }
81
-        };
82
-        if (!{}.hasOwnProperty.call(nestedCommands, args[1])) { return message.reply(`Usage of ...`); }
83
-        nestedCommands[args[1]](message, args);
80
+      };
81
+      if (!{}.hasOwnProperty.call(nestedCommands, args[1])) { return message.reply(`Usage of ...`); }
82
+      nestedCommands[args[1]](message, args);
84 83
     }
85 84
     async function restore(bot, args, message) {
86
-        message.reply('Work in progress');
85
+      if(!message.member.roles.get(role.id)) {
86
+        try{ 
87
+          message.member.roles.add(role.id);
88
+          message.reply(`Twoja rola zostala przywrocona, <@&${role.id}>`)
89
+        } catch(err) {
90
+          debug(err);
91
+          message.reply('Cos poszlo nie tak podczas przywaracanaia roli');
92
+        }
93
+      } else message.reply('Posiadasz juz swoja role derpie!')
87 94
     }
88 95
 }
89 96
 cmd.set('role', role);
97
+
98
+async function quote(bot, args, message) {
99
+  const chQuotes = '300745912571920384';
100
+  let embedAuthor;
101
+
102
+  if(!message.mentions.users.first()){
103
+    embedAuthor = {
104
+      name: args.shift()
105
+    };
106
+  } else {
107
+    args.shift();
108
+    embedAuthor = {
109
+      name: message.guild.members.resolve(message.mentions.users.first().id).displayName,
110
+      icon_url: message.mentions.users.first().displayAvatarURL
111
+    };
112
+  }
113
+
114
+  const output = {
115
+    color: 0x7F00FF,
116
+    author: embedAuthor,
117
+    description: args.join(' '),
118
+    footer: {
119
+      text: `~${new Moment().format('YYYY')}`
120
+    }
121
+  };
122
+
123
+  message.guild.channels.resolve(chQuotes).send('',{embed:output});
124
+}
125
+cmd.set('quote', quote);
126
+
90 127
 module.exports = cmd;

Loading…
Cancel
Save