Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit 47444c7f4d6c3164494a595e73e5d0515f1f4639
parent 681ed8ea7418ffc915c424ba1b4cd1a3be18faf7
Author: h <h>
Date:   Thu, 19 Mar 2020 14:33:45 +0300

repopulate commands

Diffstat:
Alib/commands/fork.ts | 5+++++
Alib/commands/github.ts | 5+++++
Alib/commands/id.ts | 14++++++++++++++
Alib/commands/ily.ts | 5+++++
Alib/commands/invite.ts | 5+++++
Alib/commands/issue.ts | 5+++++
Alib/commands/milkies.ts | 5+++++
Alib/commands/ping.ts | 5+++++
Alib/commands/prefix.ts | 5+++++
Alib/commands/say.ts | 5+++++
Alib/commands/youtube.ts | 7+++++++
Mlib/main.ts | 64----------------------------------------------------------------
12 files changed, 66 insertions(+), 64 deletions(-)

diff --git a/lib/commands/fork.ts b/lib/commands/fork.ts @@ -0,0 +1,4 @@ +export default home_scope => { + const { message, GIT_URL } = home_scope; + message.answer(`${GIT_URL}/fork`); +}+ \ No newline at end of file diff --git a/lib/commands/github.ts b/lib/commands/github.ts @@ -0,0 +1,4 @@ +export default home_scope => { + const { message, GIT_URL } = home_scope; + message.answer(`${GIT_URL}/`); +}+ \ No newline at end of file diff --git a/lib/commands/id.ts b/lib/commands/id.ts @@ -0,0 +1,13 @@ +export default home_scope => { + const { message } = home_scope + const rep = []; + ['channel', 'user', 'role'].forEach(n => + message[n + 's'].each(o => rep.push(n + ' id: `' + o.id + '`')) + ) + //joining an empty array yields an empty string which is false + const reply = rep.join(', ') || `User ID: \`${message.author.id}\` + Author: ${message.author} + Message ID: \`${message.id}\``; + console.log(`Replied: ${reply}`); + message.answer(reply); +}+ \ No newline at end of file diff --git a/lib/commands/ily.ts b/lib/commands/ily.ts @@ -0,0 +1,4 @@ +export default home_scope => { + const { message } = home_scope; + message.answer('Y-you too...'); +}+ \ No newline at end of file diff --git a/lib/commands/invite.ts b/lib/commands/invite.ts @@ -0,0 +1,4 @@ +export default home_scope => { + const { message } = home_scope; + message.answer('invite link: https://discordapp.com/api/oauth2/authorize?client_id=684895962212204748&permissions=8&scope=bot'); +}+ \ No newline at end of file diff --git a/lib/commands/issue.ts b/lib/commands/issue.ts @@ -0,0 +1,4 @@ +export default home_scope => { + const { message, GIT_URL } = home_scope; + message.answer(`${GIT_URL}/issues`); +}+ \ No newline at end of file diff --git a/lib/commands/milkies.ts b/lib/commands/milkies.ts @@ -0,0 +1,4 @@ +export default home_scope => { + const { message } = home_scope; + message.answer(`${(4 + Math.random() * 15).round_to(3)} gallons of milkies have been deposited in your mouth.`); +}+ \ No newline at end of file diff --git a/lib/commands/ping.ts b/lib/commands/ping.ts @@ -0,0 +1,4 @@ +export default home_scope => { + const { message } = home_scope; + message.answer('PONGGERS!'); +}+ \ No newline at end of file diff --git a/lib/commands/prefix.ts b/lib/commands/prefix.ts @@ -0,0 +1,4 @@ +export default home_scope => { + const { message, args, CONFIG } = home_scope; + message.answer(args.length == 1?args[0].length == 1?`Command prefix changed to: \`${CONFIG.commands.prefix = args[0]}\`.`:'You may only use a prefix that is exactly one character/symbol/grapheme/rune long.':`Current command prefix is: \`${CONFIG.commands.prefix}\`.`) +}+ \ No newline at end of file diff --git a/lib/commands/say.ts b/lib/commands/say.ts @@ -0,0 +1,4 @@ +export default home_scope => { + const { message, args } = home_scope; + message.answer(`Me-sa says: “${args.join(' ')}”`); +}+ \ No newline at end of file diff --git a/lib/commands/youtube.ts b/lib/commands/youtube.ts @@ -0,0 +1,6 @@ +import yt_search from '../api/yt_scrape'; +export default home_scope => { + const { message, args } = home_scope; + const query = args.join(' '); + yt_search({ query }).then(message.reply.bind(message)).catch(message.answer.bind(message)); +}+ \ No newline at end of file diff --git a/lib/main.ts b/lib/main.ts @@ -26,7 +26,6 @@ import DEFAULT_CONFIG from './default'; import web_search from './api/google'; import oed_lookup from './api/oxford'; import urban_search from './api/urban'; -import yt_search from './api/yt_scrape'; import { pastebin_latest, pastebin_update, pastebin_url } from './api/pastebin'; @@ -178,9 +177,6 @@ export class SimpOMatic { operator = operator.toLowerCase(); console.log('Received command:', [operator, args]); - // This should have most immediate access. - if (operator === 'ping') return message.answer('PONGGERS!'); - const commands = read_dir(`${__dirname}/commands`) .map(n => n.slice(0, -3)); if (commands.includes(operator)) @@ -198,24 +194,6 @@ export class SimpOMatic { message.reply(`All known commands (excluding aliases): \ ${joined_commands} and ${final_command}`.squeeze()); break; - } case 'id': { - if (args[0]) { - const matches = args[0].match(/<@!?(\d+)>/); - if (!matches) { - message.answer(`Please tag a user, or \ - provide no argument(s) at all. See \`!help id\`` - .squeeze()); - } else { - message.answer(`User ID: \`${matches[1]}\``); - } - break; - } - const reply = `User ID: \`${message.author.id}\` - Author: ${message.author} - Message ID: \`${message.id}\``.squeeze(); - console.log(`Replied: ${reply}`); - message.answer(reply); - break; } case 'get': { if (args.length === 0) { message.answer('To view the entire object, use the `!export` command.'); @@ -323,20 +301,6 @@ export class SimpOMatic { + 'Please see `!help alias`.'); } break; - } case 'prefix': { - if (args.length === 1) { - if (args[0].length !== 1) { - message.answer(`You may only use a prefix that is - exactly one character/symbol/grapheme/rune long.` - .squeeze()); - break; - } - CONFIG.commands.prefix = args[0]; - message.answer(`Command prefix changed to: \`${CONFIG.commands.prefix}\`.`); - break; - } - message.answer(`Current command prefix is: \`${CONFIG.commands.prefix}\`.`); - break; } case 'search': { const query = args.join(' ').toLowerCase(); const channel = message.channel as TextChannel; @@ -363,12 +327,6 @@ export class SimpOMatic { }).then(res => message.answer(res)) .catch(er => message.answer(er)); break; - } case 'youtube': { - const query = args.join(' '); - yt_search({ query }) - .then(message.reply.bind(message)) - .catch(message.answer.bind(message)); - break; } case 'define': { message.answer('Looking in the Oxford English Dictionary...'); const query = args.join(' '); @@ -446,19 +404,6 @@ export class SimpOMatic { message.channel.send(`Link: ${entry.permalink}`); }).catch(e => message.answer(`Error fetching definition:\n${e}`)); break; - } case 'milkies': { - message.answer(`${(4 + Math.random() * 15).round_to(3)} gallons \ - of milkies have been deposited in your mouth.`.squeeze()); - break; - } case 'ily': { - message.answer('Y-you too...'); - break; - } case 'say': { - message.answer(`Me-sa says: “${args.join(' ')}”`); - break; - } case 'invite': { - message.answer('Invite link: https://discordapp.com/api/oauth2/authorize?client_id=684895962212204748&permissions=8&scope=bot'); - break; } case 'export': { let export_string = export_config(CONFIG, {}); if (export_string.length > 1980) { @@ -494,15 +439,6 @@ export class SimpOMatic { }; message.channel.send(`Directories:\n\`\`\`json\n${dirs}\n\`\`\``); break; - } case 'github': { - message.answer(`${GIT_URL}/`); - break; - } case 'fork': { - message.answer(`${GIT_URL}/fork`); - break; - } case 'issue': { - message.answer(`${GIT_URL}/issues`); - break; } case '': { message.answer("That's an empty command..."); break;