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

103
LINES

< > BotCompany Repo | #1025122 // Samantha [Discord Greeter Bot, old]

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

Uses 5909K of libraries. Click here for Pure Java version (10323L/56K).

!7

cmodule GreeterBot > DynTalkBot {
  S msg = "Welcome <user>! Rules and regulations apply. And stuff.";
  S goodbyeMsg = "<user> just left us";
  long channelToGreetIn;
  
  start {
    useAGIBlueForDropPunctuation = false;
    preprocessAtSelfToMyName = false;
    dropPunctuation = false;
    
    dm_vmBus_onMessage_q discordGuildLeave(voidfunc(Map map) {
      ret unless map.get('module) == module();
      O user = rcall getUser(map.get('event));
      S name = cast rcall getName(user);
      postInChannel(channelToGreetIn, replace(goodbyeMsg, "<user>", or2(name, "an unknown user"));
    });
  }
  
  void onUserJoin(long userID, O... _) {
    S msg = replace(this.msg, "<user>", discordAt(userID));
    if (channelToGreetIn == 0) setField(channelToGreetIn := preferredChannelID);
    if (channelToGreetIn == 0) fail("Have no greeting channel"); 
    postInChannel(channelToGreetIn, msg);
  }
  
  S processSimplifiedLine(S s, O... _) {
    try answer super.processSimplifiedLine(s, _); // adding authorized users etc.
    
    new Matches m;
    
    S sOld = s;
    s = dropPrefixOrNull(myPrefix(), s);
    if (s == null) {
      print("no got prefix: " + quote(myPrefix()) + " / " + quote(sOld));
      null;
    }
    
    if (eqic(s, "prefer this channel")) {
      try answer checkAuth(_);
      long channelID = longPar channelID(_);
      if (channelID == 0) ret "No channel";
      setField(channelToGreetIn := channelID);
      ret "OK, will greet here from now on.";
    }
    
    if (eqic(s, "simulate greeting")) {
      onUserJoin(longPar userID(_), _);
      ret "Greeting simulated";
    }
    
    if (eqic(s, "get message")) ret msg;
    if (eqic(s, "get goodbye message")) ret goodbyeMsg;
    
    if (swic_trim(s, "set message:", m)) {
      try answer checkAuth(_);
      setField(msg := m.rest();
      ret "Message changed to: " + msg;
    }
    
    if (swic_trim(s, "set goodbye message:", m)) {
      try answer checkAuth(_);
      setField(goodbyeMsg := m.rest();
      ret "Goodbye message changed to: " + msg;
    }
    
    if (eqic(s, "enable")) {
      try answer checkAuth(_);
      setField(enabled := true);
      ret "Enabled. Will greet every new arrival!";
    }
    
    if (eqic(s, "disable")) {
      try answer checkAuth(_);
      setField(enabled := true);
      ret "Disabled. Will not greet anyone.";
    }
    
    if (eqic(s, "dump"))
      ret struct(objectToMap_nonTransient_singleClass GreeterBot(GreeterBot.this));
    
    if (eqic(s, "help"))
      ret trim([[
I am a simple greeter (and farewell) bot. Status: ]] + enabledDisabled(enabled) + [[. Commands:

@me **simulate greeting** -- I greet you so you can test me
@me **get message** -- show current greeting message
@me **set message: Hello <user>! Bla bla...** -- change greeting. <user> is replaced with user name
@me **simulate goodbye** -- I pretend you walked away (although I know you didn't)
@me **get goodbye message** -- show current goodbye message (what I post when people leave)
@me **set goodbye message: <user> just left us
@me **prefer this channel** -- posts greetings in the channel you write this in
@me **enable/disable** -- enable/disable the auto-greeting
@me **masters**/**add master**/**delete master** -- change bot ownership
@me **source**/**support channel** -- see sources or join the support discord

[Bot made by https://BotCompany.de]
]]).replace("@me", atSelf());

    null;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025122
Snippet name: Samantha [Discord Greeter Bot, old]
Eternal ID of this version: #1025122/31
Text MD5: 1afebf92c6d018dff10f3eeccce4118f
Transpilation MD5: 67257a8873f9bb17a8e4d71d9676173b
Author: stefan
Category: javax / bots
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-10 00:01:56
Source code size: 3534 bytes / 103 lines
Pitched / IR pitched: No / No
Views / Downloads: 345 / 876
Version history: 30 change(s)
Referenced in: [show references]