!7 concept Game{ S shortName, name; } concept Wanted{ long Id; S name, game; } !include once #1026298 // use JDA 4.0 standardBot1 TomiiBoiDiscordBot { allServers { start{ db(); gamesCRUD = new CRUD(Game); wantedCRUD = new CRUD(Wanted); } transient CRUD gamesCRUD; transient CRUD wantedCRUD; visual jtabs( "Main", super, "Games", gamesCRUD.visualize(), "Wanted", wantedCRUD.visualize()); switchable S backendName = "tomiiBoiQA"; //switchable bool newVersion = true; void grabChannels { print("Grabbing channels"); for (Guild guild : discord.getGuilds()) { virtual Server server = guildToServer(guild); for (GuildChannel c : guild.getChannels()) dm_call(backendName, "addChannel", server, str(c.getIdLong()), c.getName()); } } virtual Server guildToServer(Guild guild) { ret guild == null ? null : dm_callOpt(backendName, "addServer", str(guild.getIdLong()), guild.getName()); } } init { if (myName == null) setField(myName := "Tomii"); preprocessAtSelfToMyName = true; dropPunctuation = false; escapeAtEveryone = true; reactToBots = false; dm_registerAs("tomiiBoiDiscordBot"); } sync S processSimplifiedLine(S s, O... _) { try answer super.processSimplifiedLine(s, _); new Matches m; if (swic_trim(s, "gbot:", m)) ret gbot(m.rest(), paramsToMap(_)); O dbBot = dm_mainClass(backendName); temp tempSetTL((ThreadLocal) getOpt(dbBot, 'opt_noDefault), true); optPar Message msg; // channel logic MessageChannel channel = msg.getChannel(); if (channel != null) { virtual Channel backendChannel = dm_call(backendName, "channelForID", str(channel.getIdLong())); if (isFalse(getOpt botEnabled(backendChannel))) null; } // guild logic Guild guild = msg == null ? null : msg.getGuild(); // add guild to server list virtual Server server = guildToServer(guild); //if (newVersion) if (swic(s, "!zocken ", m)) { S game = m.rest(); Game gameObject = conceptWhereIC Game(shortName :=game); if (gameObject !=null) game =gameObject.name; else { ret "dieses Spiel kenne ich noch nicht"; } long Id = msg.getMember().getIdLong(); S name = msg.getMember().getUser().getName(); uniqIC Wanted(+Id,+name,+game); ret "@here " + discordAt(Id) + " will " + game + " zocken!"; } if (swic(s, "!who ",m)){ S game = m.rest(); Game gameObject = conceptWhereIC Game(shortName :=game); if (gameObject !=null) game =gameObject.name; else { ret "dieses Spiel kenne ich noch nicht"; } L list = conceptsWhereIC Wanted(+game); if (l(list) > 1) ret joinWithComma(map(list, w -> discordAt(w.Id))) + " wollen " + game + " spielen!"; else if (l(list) == 1) ret joinWithComma(map(list, w -> discordAt(w.Id))) + " wil " + game + " spielen!"; else ret "nimeand will dieses Game zurzeit spielen"; } ret (S) call(dbBot, "answer", s, +server); /*Cl categories = dm_callOpt(backendName, "categoriesForServer", server); temp tempSetTL((ThreadLocal) getOpt(dbBot, "categoriesForRequest"), categories); ret (S) call(dbBot, 'answer, s, "en");*/ } S gbot(S query, Map map, O... _) { LS l = regexpICFullMatch_groups("(\\d+) results? for[ :](.+)", query); int results = 1; if (l != null) { results = parseInt(first(l)); query = unquote(trim(last(l))); } bool safeSearch = !discord_isNSFWChannel_gen(map.get('channel)); ret discord_google(query, paramsPlus(_, +results, +safeSearch)); } }