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

81
LINES

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

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

Uses 10819K of libraries. Click here for Pure Java version (19007L/101K).

!7

!include once #1026298 // use JDA 4.0

standardBot1 TomiiBoiDiscordBot {
  allServers {
    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)
      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));
  }
}

Author comment

Began life as a copy of #1026479

download  show line numbers  debug dex   

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

No comments. add comment

Snippet ID: #1026494
Snippet name: Tomii Boi Discord Bot [in-OS db version, use with #1028036]
Eternal ID of this version: #1026494/22
Text MD5: 72f2b8c027f967e236a75bc86bb5860e
Transpilation MD5: 425b6c624a51e7fe53e93d8c7b2344e8
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-11 13:54:16
Source code size: 2440 bytes / 81 lines
Pitched / IR pitched: No / No
Views / Downloads: 109 / 3027
Version history: 21 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1026494 & http://1026494.tinybrain.de