about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2021-02-24 12:09:47 -0800
committerBrian Chu <brianmchu42@gmail.com>2021-02-24 12:09:47 -0800
commitaf2acbac4453ca5164b1a769dd137892e5fe7c53 (patch)
treeb54071611cbe283ecf578b26d0d9cdb4d363ad08
parent420a39c8f16761cad55f49addc5f20e3c0aaf26e (diff)
downloadbytheway-af2acbac4453ca5164b1a769dd137892e5fe7c53.tar.gz
add message responses main
-rw-r--r--index.js49
1 files changed, 47 insertions, 2 deletions
diff --git a/index.js b/index.js
index 0d13674..c03ab78 100644
--- a/index.js
+++ b/index.js
@@ -1,11 +1,56 @@
 import { config } from 'dotenv'
-config()
-
 import { Client } from 'discord.js'
+import DisConf from './config.json'
+config()
 const client = new Client()
 
 client.once('ready', () => {
   console.log('ByTheWay, your bot is ready')
 })
 
+client.on('message', message => {
+  if (!message.content.startsWith(DisConf.prefix) | message.author.bot) return
+
+  const args = message.content.slice(DisConf.prefix.length).trim().split(/ +/)
+  const command = args.shift().toLowerCase()
+
+  if (command === 'interject') {
+    message.channel.send('I\'d just like to interject for a moment. What you’re referring to as Linux, is in fact, GNU/Linux, or as I’ve recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called “Linux”, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project. There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine’s resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called “Linux” distributions are really distributions of GNU/Linux.')
+  } else if (command === 'btw') {
+    const roles = message.member.roles.cache.array().map(x => x.name)
+    for (const distro of DisConf.distros) {
+      if (roles.includes(distro)) {
+        message.channel.send(`I use ${distro} Linux, btw`)
+        break
+      }
+    }
+  } else if (command === 'assign') {
+    if (!args.length) {
+      return message.channel.send(`You didn't provide a distro! Tux the penguin is very sad.`)
+    } else if (args.length > 1) {
+      return message.channel.send(`You can use more than one distro when you dual boot, but not with this bot`)
+    }
+
+    const toRemove = message.member.roles.cache.filter(x => DisConf.distros.includes(x.name))
+    const toAdd = message.guild.roles.cache.filter(x => x.name === args[0])
+    console.log(toRemove)
+    console.log(toAdd)
+    message.member.roles.remove(toRemove)
+      .then(() => message.channel.send('Role reset'))
+      .catch(err => {
+        message.channel.send('Oops something happened while resetting your role')
+        console.log(err)
+      })
+
+    message.member.roles.add(toAdd)
+      .then(() => message.channel.send(`You're now a proud user of ${args[0]} Linux!`))
+      .catch(err => {
+        message.channel.send('Oops something happened while adding your role')
+        console.log(err)
+      })
+  }
+})
+
+
+
 client.login(process.env.TOKEN)