Warning: session_start(): open(/var/lib/php/sessions/sess_kaa9h61gncfrq2tbp9fus0ut2s, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
cmodule NLRulesBot extends DynTalkBot2<.ByServer> {
start {
makeByServer = () -> new ByServer;
useAGIBlueForDropPunctuation = false;
preprocessAtSelfToMyName = false;
dropPunctuation = false;
}
sclass Rule {
GlobalID globalID = aGlobalIDObj();
bool enabled = true;
S text;
*() {} *(S *text) {}
}
S renderRule(Rule r) {
ret r == null ? null : "Rule " + r.globalID +
(enabled ? "" : " [disabled]") + ": " +
r.text;
}
class ByServer extends DynTalkBot2.ByServer {
new L rules;
new Set priorityChannels; // where we always respond
bool enableMagicQuotes = true;
synchronized S processSimplifiedLine(S s, O... _) {
try answer super.processSimplifiedLine(s, _);
new Matches m;
S s2 = dropMyPrefixOrNull(s);
if (s2 != null) s = s2;
else if (!contains(priorityChannels, optPar channelID(_))) null;
if "on * say *|on *, image-google X|on *, google X" {
Rule r = firstWhereIC(rules, text := s);
if (r != null) ret "Rule exists: " + r.globalID;
rules.add(r = new Rule(s));
change();
ret "Rule added with ID " + r.globalID;
}
if "rules"
ret lines(map(r -> renderRule(r), rules));
if "delete rule *|delete rule with id *" {
try answer checkAuth(_);
Rule r = firstWhere(rules, globalID := GlobalID($1));
if (r == null) ret "Rule " + $1 + " not found";
rules.remove(r);
change();
ret "Rule deleted, " + nRule(rules) + " remain";
}
if "priority channel on" {
try answer checkAuth(_);
priorityChannels.add(longOptPar channelID(_)); change();
ret "OK";
}
if "priority channel off" {
try answer checkAuth(_);
priorityChannels.remove(optPar channelID(_)); change();
ret "OK";
}
if "disable magic quotes" {
try answer checkAuth(_);
enableMagicQuotes = false; change();
ret "OK";
}
if (eqic(s, "help"))
ret ltrim([[
I execute simple English rules.
Stuff to say.
@me on "hello bot" say "who are you"
@me masters / add master / delete master
@me help / support / source code
[Bot made by https://BotCompany.de]
]]).replace("@me", atSelf());
// find rule to execute
for (Rule r : rules) pcall {
if (!r.enabled) continue;
if (match("on * say *", r.text, m)) {
S in = $1, out = $2;
if (match(in, s))
ret out;
}
if (match("on keyword * say *", r.text, m)) {
S in = $1, out = $2;
if (find(in, s))
ret out;
}
if (match("on *, image-google X", r.text, m))
if (flexMatchIC(replaceWord($1, "X", "*"), s, m)) {
bool nsfw = discord_isNSFWChannel_gen(optPar channel(_));
print(+nsfw);
BufferedImage img = nsfw ? quickVisualize_nsfw($1) : quickVisualize($1);
if (img == null) ret "No image found, sorry!";
postImage(paramsToMap(_), uploadToImageServer(img, $1));
}
if (match("on *, google X", r.text, m))
if (flexMatchIC(replaceWord($1, "X", "*"), s, m)) {
bool nsfw = discord_isNSFWChannel_gen(optPar channel(_));
print(+nsfw);
ret discord_google($1, results := 1, safeSearch := !nsfw);
}
}
if "download" {
optPar Guild guild;
optPar MessageChannel channel;
if (guild == null) ret "Do this in a guild";
ret serveGuildBackup(channel, guild,
structure_nullingInstancesOfClass(_getClass(module()), ByServer.this));
}
if (enableMagicQuotes)
try answer answer_magicQuoteInput(s);
null;
}
}
S serveGuildBackup(MessageChannel channel, Guild guild, S data) {
S baseName = urlencode(jda_selfUserName(discord))
+ "-" + guild.getIdLong() + "-" + ymd_minus_hms();
S zipName = baseName + ".zip";
File zip = programFile("backups/" + zipName);
createZipFileWithSingleTextFile(zip, baseName + ".txt", data);
channel.sendMessage("Here's my latest brain contents for this guild.").addFile(zip).queue();
null;
}
}