Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

148
LINES

< > BotCompany Repo | #1029471 // Tomii Boi Discord Bot Extension [in-OS db version, use with #1028036]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 11163K of libraries. Click here for Pure Java version (22339L/122K).

!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<Game> gamesCRUD;
    transient CRUD<Wanted> 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<Wanted> 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<S> 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));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, qsqiayxyrbia, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1029471
Snippet name: Tomii Boi Discord Bot Extension [in-OS db version, use with #1028036]
Eternal ID of this version: #1029471/41
Text MD5: ac1ca46266a16a6e04ccb6b44e023347
Transpilation MD5: d419c0358e6fb65d5deef6839dc9896e
Author: jarvis
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-11 17:47:18
Source code size: 4474 bytes / 148 lines
Pitched / IR pitched: No / No
Views / Downloads: 159 / 63547
Version history: 40 change(s)
Referenced in: [show references]