Halibot / halibot

The world's greatest saltwater multi-protocol chat bot framework!
https://halibot.fish
BSD 3-Clause "New" or "Revised" License
7 stars 6 forks source link

Resource identifier (RI) abstraction layer #135

Open sjrct opened 5 years ago

sjrct commented 5 years ago

RI logic right now is in various places throughout the code base. We split and join on "/" in a bunch of places. We really should have that and other RI-specific logic in an abstract layer. Could be a class that looks like a string, although maybe a module with functions that take strings to interpret as RIs are better.

richteer commented 5 years ago

To add to this, I'd like this kind of behavior represented somehow, either by transparent class, or something else:

match_agent("irc", "irc/##halibot") -> True

match_ri("irc/##halibot", "irc/##halibot") -> True
match_ri("irc", "irc/##halibot") -> False

ri("irc/##halibot").agents() -> "irc"
ri("irc/##halibot").modules() -> ""
ri("irc/##halibot").meta() -> "##halibot"

Largely tossing ideas out there, I don't have anything coherent in mind yet.

richteer commented 5 years ago

Here's another thought: maybe there should be a way to retrieve values from a dict based on an RI, and have it transparently apply any hierarchies:

{
  "filters": {
    "inbound": {
      "irc": ["test"],
      "irc/##halibot": ["foobar"]
    }
  }
}
get_filters(ri="irc/##halibot", childonly=True) # returns ["foobar"]
get_filters(ri="irc/##halibot", parentonly=True) # returns ["test"]
get_filters(ri="irc/##halibot") # returns ["foobar, "test"]
get_filters(ri="irc/##halibot", parentfirst=True) # returns [ "test", "foobar"]