Skip to content

Commit

Permalink
feat: Adjustments to make functionality more agnostic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Moffitt committed Apr 8, 2022
1 parent 54c3e81 commit f85e132
Show file tree
Hide file tree
Showing 6 changed files with 756 additions and 10,864 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
# Slack Catbot

Run as a node service
Run as a node service. For example, using systemctl:

/etc/systemd/system/catbot.service
```
[Unit]
Description=Catbot
After=network.target
[Service]
Environment=NODE_PORT=3001
User=root
Restart=always
RestartSec=1000ms
StandardOutput=/var/log/catbotlog.log
StandardError=/var/log/catboterr.log
ExecStart=/usr/local/bin/node /usr/local/bin/slack-catbot/index.js
RuntimeMaxSec=14400s
[Install]
WantedBy=multi-user.target
```

This will allow him to start on boot.
`systemctl enable catbot.service`

Start or stop
`systemctl start/stop catbot`

Create a bot.json file off the example.

Refer to rooms and people by their IDs, not canonical names. You can find Room IDs by expanding the channel info of a room. The ID is usually at the bottom. A member ID is in a user's profile, under the "More" menu.

Create a slack bot and populate the config with the access token and name of the bot.
26 changes: 22 additions & 4 deletions bot-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,43 @@
"boss": [
"{USER ID NOT NAME}"
],
"debug": [
"{ROOM ID TO LOG DEBUGGING}"
],
"config": {
"generator": {
},
"pokemon": {
"regex": "^pokemon.+"
},
"reset": {
"regex": "!die|!goaway|!reset"
"regex": "^pokemon.+",
"groups": []
},
"speak": {
"regex": "catbot"
},
"bukkit": {
"bukkit": "{URL OF BUKKIT SERVER}",
"regex": "^bukkit.+|^!(.+).gif$|^!(.+).jpeg$|^!(.+).jpg$|^!(.+).png$"
},
"github": {
"username": "{GITHUB USERNAME}",
"password": "{GITHUB PASSWORD}",
"regex": "^gh .+"
},
"doggo": {
"regex": "!doggo|!pupper|!woofer|!doge|!shoob|!wrinkler|!puggo|!floofer|!goodboye"
},
"spotify": {
"regex": "^!spotify|^!song",
"password": "{SPOTIFY API KEY}",
"skip": "skip-endpoint.php",
"playing": "now-playing-endpoint.php",
"timeout": 300000
},
"weather": {
"regex": "!weather",
"apikey": "{OPENWEATHER API KEY}",
"lat": "34.478263",
"lon": "-114.362723"
}
}
}
61 changes: 30 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ const bukkit = require('./modules/bukkit.js');
const pokemon = require('./modules/pokemon.js');
const github = require('./modules/github.js');
const doggos = require('./modules/doggo.js');
const spotify = require('./modules/spotify.js');
// const spotify = require('./modules/spotify.js');
const weather = require('./modules/weather.js');

const Accessor = require('Accessor');

const fork = require('child_process').fork;
const cronrunner = fork(__dirname + '/cronrunner.js');

Expand Down Expand Up @@ -65,12 +63,14 @@ let __channels = [];
let __groups = [];
let __users = [];

// The Brain where he gets his words from. You may need to create this file. Catbot does not add to this file.
let markov = __dirname + '/markov.txt';

const hal = new megahal(4);

bot.on('start', function () {

// Public channels
let _channels = bot.getChannels();
let channels = _channels._value.channels;
for (let i in channels) {
Expand All @@ -79,6 +79,7 @@ bot.on('start', function () {
}
}

// Private channels
let _groups = bot.getGroups();
let groups = _groups._value.groups;
for (let i in groups) {
Expand All @@ -87,6 +88,7 @@ bot.on('start', function () {
}
}

// Users
let _users = bot.getUsers();
let users = _users._value.users;
for (let i in users) {
Expand All @@ -95,6 +97,7 @@ bot.on('start', function () {
}
}

// Load the brain into MegaHAL
fs.readFile(markov, 'utf8', function (err, data) {
hal.addMass(data);
});
Expand All @@ -115,10 +118,6 @@ bot.on('message', function (data) {
let whom = data.user;
let msg = message.split(' ');

if (meetsCriteria('data', data)) {

}

if (meetsCriteria('weather', data)) {

if (canDo()) {
Expand Down Expand Up @@ -258,29 +257,29 @@ bot.on('message', function (data) {

}

if (meetsCriteria('spotify', data)) {

if (canDo()) {

warmUp();

let channel = data.channel;

let msg = message.split(' ');
let clean = msg.shift();
msg = msg.join(' ');

spotify.call(msg, whom).then(function (res) {
say(res, channel);
cooldown();
}, function (error) {
say(error, channel);
cooldown();
});

}

}
// if (meetsCriteria('spotify', data)) {
//
// if (canDo()) {
//
// warmUp();
//
// let channel = data.channel;
//
// let msg = message.split(' ');
// let clean = msg.shift();
// msg = msg.join(' ');
//
// spotify.call(msg, whom).then(function (res) {
// say(res, channel);
// cooldown();
// }, function (error) {
// say(error, channel);
// cooldown();
// });
//
// }
//
// }

if (meetsCriteria('bukkit', data)) {

Expand All @@ -302,7 +301,7 @@ bot.on('message', function (data) {
if (gif === 'help' || gif === '?') {

let response = [
'Output a gif from Ians Bukkit site. https://bukkit.ianmoffitt.co',
'Output a gif from a Bukkit site. (' + config.config.bukkit.bukkit + ')',
'Format: `!name.gif` or `bukkit name.gif`'
];

Expand Down
3 changes: 2 additions & 1 deletion modules/bukkit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const util = require('util');
const request = require('request');
const https = require('https');
const config = require('../bot.json');

module.exports = {

bukkit: 'bukkit.ianmoffitt.co',
bukkit: config.config.bukkit.bukkit,

get: function (gif) {

Expand Down
2 changes: 1 addition & 1 deletion modules/pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
],

endpoint: 'http://pokeapi.co/api/v2/pokemon/%s',
maximum: 802,
maximum: 898,

retrieve: function (msg) {

Expand Down
Loading

0 comments on commit f85e132

Please sign in to comment.