فهرست منبع

Fix printing guide on indirect ping

denikson 6 سال پیش
والد
کامیت
44068fe818
1فایلهای تغییر یافته به همراه25 افزوده شده و 22 حذف شده
  1. 25 22
      main.js

+ 25 - 22
main.js

@@ -147,30 +147,33 @@ client.on("message", m => {
     }
 
     if (m.mentions.users.first().id == client.user.id) {
-        let content = m.cleanContent
-            .substring(`@${client.user.username} `.length);
-        let lowerCaseContent = content.toLowerCase().trim();
-        for (let c in commands) {
-            if (lowerCaseContent.startsWith(c)) {
-                commands[c](m, content);
-                return;
+        let content = m.cleanContent.trim();
+        if(content.startsWith(`@${client.user.username}`)) {
+            content = content
+                .substring(`@${client.user.username} `.length);
+            let lowerCaseContent = content.toLowerCase().trim();
+            for (let c in commands) {
+                if (lowerCaseContent.startsWith(c)) {
+                    commands[c](m, content);
+                    return;
+                }
             }
-        }
 
-        if (lowerCaseContent.length > 0) {
-            let parts = lowerCaseContent.trim().split(" ");
-            let guide = db
-                .get("guides")
-                .map(g => Object.assign({parts: g.name.toLowerCase().split(" ")}, g))
-                .sortBy(g => g.parts.length)
-                .maxBy(k => db._.intersection(parts, k.parts).length)
-                .value();
-            let hits =
-                guide !== undefined &&
-                db._.intersection(guide.name.toLowerCase().split(" "), parts).length > 0;
-            if (hits) {
-                m.channel.send(guide.content);
-                return;
+            if (lowerCaseContent.length > 0) {
+                let parts = lowerCaseContent.trim().split(" ");
+                let guide = db
+                    .get("guides")
+                    .map(g => Object.assign({parts: g.name.toLowerCase().split(" ")}, g))
+                    .sortBy(g => g.parts.length)
+                    .maxBy(k => db._.intersection(parts, k.parts).length)
+                    .value();
+                let hits =
+                    guide !== undefined &&
+                    db._.intersection(guide.name.toLowerCase().split(" "), parts).length > 0;
+                if (hits) {
+                    m.channel.send(guide.content);
+                    return;
+                }
             }
         }