mirror of
https://github.com/jcreek/MupBot.git
synced 2026-07-13 10:53:44 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1fd8fcc5ad | |||
| 01ef3cfb02 | |||
| 202d22b28b | |||
| e6950df529 |
+65
-2
@@ -3,9 +3,13 @@ const axios = require('axios');
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('got');
|
||||
|
||||
let enableModCommands = false;
|
||||
const adultChannelName = 'adult-only-chat';
|
||||
|
||||
module.exports = {
|
||||
dailyTasks: function (client) {
|
||||
sendDailyDilbert(client);
|
||||
sendDailyWorkChronicles(client);
|
||||
},
|
||||
matchCommand: function (Discord, config, logger, message, command, args) {
|
||||
switch(command) {
|
||||
@@ -13,8 +17,28 @@ module.exports = {
|
||||
commandHelp(Discord, config, logger, message, command, args);
|
||||
break;
|
||||
case 'ud':
|
||||
commandUrbanDictionary(Discord, config, logger, message, command, args);
|
||||
if (message.channel.name === adultChannelName) {
|
||||
commandUrbanDictionary(Discord, config, logger, message, command, args);
|
||||
}
|
||||
else {
|
||||
const channel = message.client.channels.cache.find((channel) => channel.name === adultChannelName);
|
||||
message.channel.send(`This command is restricted to the <#${channel.id}> channel.`);
|
||||
}
|
||||
break;
|
||||
case 'enablemod':
|
||||
commandModEnable(Discord, config, logger, message, command, args);
|
||||
break;
|
||||
case 'disablemod':
|
||||
commandModDisable(Discord, config, logger, message, command, args);
|
||||
break;
|
||||
case 'examplemod':
|
||||
if(enableModCommands) {
|
||||
commandModExample(Discord, config, logger, message, command, args);
|
||||
}
|
||||
else {
|
||||
message.channel.send(`That command is currently disabled. To find out more visit ${config.github_url}`);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
message.channel.send(`That command is not one I know yet - but you could add it! To find out more visit ${config.github_url}`);
|
||||
}
|
||||
@@ -43,7 +67,7 @@ The commands available to you are:
|
||||
}
|
||||
}
|
||||
|
||||
function commandUrbanDictionary(Discord, config, logger, message, command, args) {
|
||||
function commandUrbanDictionary (Discord, config, logger, message, command, args) {
|
||||
if (!args.length) {
|
||||
//If the command is used incorrectly without arguments
|
||||
return message.channel.send(`You didn't provide any arguments, ${message.author}!\nCorrect Usage: \`${config.prefix}ud <query>\``);
|
||||
@@ -97,6 +121,18 @@ function commandUrbanDictionary(Discord, config, logger, message, command, args)
|
||||
}
|
||||
}
|
||||
|
||||
function commandModEnable (Discord, config, logger, message, command, args) {
|
||||
enableModCommands = true;
|
||||
}
|
||||
|
||||
function commandModDisable (Discord, config, logger, message, command, args) {
|
||||
enableModCommands = false;
|
||||
}
|
||||
|
||||
function commandModExample (Discord, config, logger, message, command, args) {
|
||||
// This would be a Mod command that can be enabled and disabled using the enableModCommands variable
|
||||
}
|
||||
|
||||
async function sendDailyDilbert(client) {
|
||||
let comicImageUrl;
|
||||
|
||||
@@ -123,3 +159,30 @@ async function sendDailyDilbert(client) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function sendDailyWorkChronicles(client) {
|
||||
let comicImageUrl;
|
||||
|
||||
// Scrape today's Work Chronicles comic from the website
|
||||
try {
|
||||
const comicUrl = 'https://workchronicles.com/';
|
||||
|
||||
// Need to match the first instance of class wp-block-latest-posts__featured-image and return the src property, which is the comic image
|
||||
const response = await got(comicUrl);
|
||||
const $ = cheerio.load(response.body);
|
||||
|
||||
comicImageUrl = $('.wp-block-latest-posts__featured-image:first').attr('src');
|
||||
} catch (error) {
|
||||
logger.error('Failed to get the Work Chronicles comic image url', error);
|
||||
}
|
||||
|
||||
if (comicImageUrl.length > 0) {
|
||||
// Find the channel and send the comic
|
||||
try {
|
||||
const channel = client.channels.cache.find((channel) => channel.name === 'daily-work-chronicles');
|
||||
channel.send(comicImageUrl);
|
||||
} catch (error) {
|
||||
logger.error('Failed to find the daily Work Chronicles channel and send a message', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user