Libraryless. Click here for Pure Java version (9161L/63K/203K).
!7 !include #1007827 // Slack Bot sbool doSlack = true; !include #1008066 // SelectBot with guess_match static Set<S> botNames = asSet(splitAtSpace("time greet greetbot random thanks thanksbot bye byebot byeall")); static O extensionModule; static Throwable extensionModuleError; extend SelectBot { S name; } concept ExtensionModule { S snippetID; } p { // DB start & migration bootstrapConceptsFrom(#1007829); db(); if (countConcepts(SelectBot) == 1) cset(uniq(SelectBot), name := "greet"); reloadExtensionModule(); slackSpeed = 1000; if (doSlack) initSlackBot(); dediSay("Back online!"); if (doSlack) slackBotLoop(); } answer { s = trim(s); if (startsWith(s, "!data:", m)) ret struct(getBot($1)); if (startsWith(s, "!plus:", m)) ret struct(keysWithValue(getBot($1).examples, true)); if (startsWith(s, "!minus:", m)) ret struct(keysWithValue(getBot($1).examples, false)); if (eq(s, "!dedicated")) ret yesno(dedicated()); if (eq(s, "!channel")) { Map map = objectToMap(channel!); map.remove("token"); ret structForUser(map); } // Train bots for (S bot : botNames) { if (startsWithWord(s, "!" + bot, m)) { getBot(bot).put($1, true); ret "ok"; } if (startsWithWord(s, "!no" + bot, m)) { getBot(bot).put($1, false); ret "ok"; } } // general if (eq(s, "!reload")) { actionsAfterPost.add(f restart); ret "krasser reload"; } if (eq(s, "!source")) ret progLink(); if (eq(s, "!help")) ret botAutoHelp(); // for debugging if (eq(s, "!username")) ret slackUserName!; // extension module if (eq(s, "!ext")) ret "Yo: " + joinWithSpace(collect(list(ExtensionModule), "snippetID")); if (eq(s, "!ext reload")) { reloadExtensionModule(); ret "OK"; } if (eq(s, "!authed")) ret yn(authed()); if (authed()) { if (startsWithWord(s, "!ext", m)) { cset(uniq(ExtensionModule), snippetID := fsI($1)); reloadExtensionModule(); ret "OK"; } } // match on bots if (isMatch("greet", s)) ret s + " => hi!"; if (isMatch("time", s)) ret s + " => It is " + hmsWithColons(); if (isMatch("random", s)) ret s + " => " + aGlobalID(); if (isMatch("thanks", s)) ret s + " => " + "You're welcome."; if (isMatch("bye", s) || isMatch("byeall", s)) ret s + " => " + "Bye bye!"; try answer callStaticAnswerMethod(extensionModule, s); } static bool isMatch(S bot, S s) { ret dedicated() && isMatch2(bot, s) || isMatch2(bot + "bot", s); } static bool isMatch2(S bot, S s) { ret isTrue(getBot(bot).get(s)); } static SelectBot getBot(S name) { ret uniq(SelectBot, +name); } static L<S> botAutoHelp_commands() { L<S> cmds = _botAutoHelp_commands(); for (S bot : botNames) addAll(cmds, "!" + bot, "!no" + bot); ret cmds; } static bool dedicated() { Channel c = channel!; ret c == null ? false : c.dedicated; } sbool authed() { ret eq(slackUserName!, "drjava"); } svoid reloadExtensionModule { cleanUp(extensionModule); extensionModule = null; extensionModuleError = null; for (ExtensionModule m) { try { extensionModule = run(m.snippetID); } catch e { extensionModuleError = e; } break; } }
Began life as a copy of #1007829
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, lulzaavyztxj, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1008059 |
Snippet name: | Celestia Slack Bot 2 [LIVE, multiple modules] |
Eternal ID of this version: | #1008059/35 |
Text MD5: | 49e3e9c43e59ef46e884811c28387b3f |
Transpilation MD5: | 7eca48a69b2753bb3ead8a3fe2267c7a |
Author: | stefan |
Category: | javax / slack bots |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-05-06 16:34:28 |
Source code size: | 3369 bytes / 140 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 572 / 823 |
Version history: | 34 change(s) |
Referenced in: | [show references] |