This commit is contained in:
Ryan Voots 2020-08-22 15:00:46 -07:00
parent 77190cad6e
commit 7f5544c2d8
3 changed files with 67 additions and 36 deletions

89
bot.js
View file

@ -1,40 +1,57 @@
var Discord = require('discord.js');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
var bot = new Discord.Client();
var axios = require('axios');
bot.on('ready', () => {
console.log(`Logged in as ${bot.user.tag}!`);
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
token: auth.token,
autorun: true
bot.on('message', msg => {
if (msg.author.username == bot.user.username) {
return
}
let foundme = msg.mentions.users.find(user => user.username == bot.user.username);
let url = "http://192.168.196.2:1092/request";
let author = msg.author.username;
let perlbot_request = {
"body": msg.content,
"orig_body": msg.content,
"who": author,
"channel": "#"+msg.channel.id,
"server": "discord.gg",
"addressed": false
};
if (foundme) {
perlbot_request.addressed = true;
// console.log(foundme);
// remove the addressed part
perlbot_request.body = perlbot_request.body.replace(`<@!${bot.user.id}>`, "");
// console.log(perlbot_request, bot.user, foundme);
}
if (msg.channel.type == 'dm') {
perlbot_request.addressed = true;
}
return axios({
method: 'POST',
url: url,
data: perlbot_request
}).then(response => {
console.log(response.data);
if (response.data.body) {
msg.reply(`${response.data.body}`);
}
})
});
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
// Our bot needs to know if it will execute a command
// It will listen for messages that will start with `!`
if (message.substring(0, 1) == '!') {
var args = message.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
// !ping
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pong!'
});
break;
// Just add any case commands if you want to..
}
}
});
bot.login("token")
bot.login(auth.token)

13
package-lock.json generated
View file

@ -47,6 +47,14 @@
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"axios": {
"version": "0.20.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.20.0.tgz",
"integrity": "sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"color": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz",
@ -162,6 +170,11 @@
"resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz",
"integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw=="
},
"follow-redirects": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz",
"integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA=="
},
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",

View file

@ -5,6 +5,7 @@
"main": "bot.js",
"author": "Ryan Voots",
"dependencies": {
"axios": "^0.20.0",
"discord.js": "^12.3.1",
"winston": "^3.3.3"
}