!7 concept Game{ S shortName, name; } concept Wanted{ long Id, timeout, guildid; 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(); long guildid = guild.getIdLong(); // add guild to server list virtual Server server = guildToServer(guild); //if (newVersion) if (eqic(s, "!help")) ret trimAllLines([[Type !play followed by a game of your choice to signal that you want to play this game. The bot will remember you wanting to play this game for 30 minutes. During these 30 minutes if anyone types !who followed by your game the bot will show who wanted to play this game in the last 30 minutes respectively]]); if (swic(s, "!play ", m)) { S game = m.rest(); Game gameObject = conceptWhereIC Game(shortName :=game); if (gameObject !=null) game =gameObject.name; else { ret "I dont know this game"; } long Id = msg.getMember().getIdLong(); S name = msg.getMember().getUser().getName(); cset(uniqIC Wanted(+Id,+name,+game,+guildid),timeout :=now()+1000*1800); deleteConcepts(filter(list(Wanted),w -> w.timeout <= now())); ret "@here " + discordAt(Id) + " wants to play " + game; } if (swic(s, "!who ",m)){ S game = m.rest(); Game gameObject = conceptWhereIC Game(shortName :=game); if (gameObject !=null) game =gameObject.name; else { ret "I dont know this game"; } deleteConcepts(filter(list(Wanted),w -> w.timeout <= now())); L list = conceptsWhereIC Wanted(+game,+guildid); if (l(list) > 1) ret joinWithComma(map(list, w -> discordAt(w.Id))) + " want to play " + game; else if (l(list) == 1) ret joinWithComma(map(list, w -> discordAt(w.Id))) + " wants to play " + game; else ret "Nobody wants to play this game right now"; } 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)); } }