UNPKG

cordlr-pinga

Version:
62 lines (54 loc) 1.79 kB
// Loading the CordlrPlugin library for helpers and more functionalities const CordlrPlugin = require('cordlr-plugin') // Load other NPM dependencies const ping = require('ping') // Create Plugin Class class PingaPlugin extends CordlrPlugin { constructor (bot, config) { super(bot, config) // Always use super to setup the plugin and important values // Set Meta Data of your Plugin to make it readable by Cordlr loaders and help plugins this.name = 'Pinga' this.description = 'Simple demo plugin for Cordlr giving the option to send pings to a hostname' // Define commands this.commands = { 'ping': { 'usage': '<hostname>', 'function': 'ping' }, 'multiping': { 'usage': '<hostname> <hostname> <hostname> ...', 'function': 'pingMultiple' } } } // Always pass in message, args, flags to handle incoming messages ping (message, args, flags) { if (!args.length) { this.sendInfo(message, 'Please add a hostname', 'No hostname specified', null, 'error') return false } ping.sys.probe(args[0], (isAlive) => { let output = false let color = false if (isAlive) { output = args[0] + ' is online and responded to the ping!' color = 5227861 } else { output = args[0] + ' is offline and did not respond to the ping!' color = 16711680 } if (output) { const channel = message.channel channel.sendEmbed({ title: 'Ping check for ' + args[0], description: output, color: color, footer: { text: 'Cordlr Pinga Plugin' } }) } }) } } module.exports = PingaPlugin