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

ContextModule #4

Open richteer opened 9 years ago

richteer commented 9 years ago

Modules that automatically handle and keep separate local data for certain contexts. This means that code only needs to be written once, and automagically switches contexts when messages from difference sources are received.

This should be seamless to the module developer. That way, they can store specific information about a particular user, chat rooms, etc. and be accessed seamlessly without the module developer ever needing to implement some kind of context manager. Thus, it should be assumed that messages received from different sources (different agents, chat rooms, etc.) are independent of one another, and thus unaware of each other.

Consider the following sample ContextModule, FavoriteFood.

class FavoriteFood(ContextModule):

  food = ""

  def handleMessage(self, msg):
    if msg["body"].startswith("!what"):
      self.reply("Your favorite food is {}".format(self.food))
    elif msg["body"].startswith("!set"):
      self.food = msg["body"].replace("!set ", "")

(Note: this is an example of #3 being useful to resolve)

Now, if users Alice and Bob were to both send !set <food>, with different values for <food>, sending !food should cause the bot to respond with two different messages, despite the same local variable name being used.

sjrct commented 9 years ago

Nifty nifty. Although it may not be as easy to implement, it might be useful to have different levels of granularity of the respect. Like per-room instead of per-person. For example, a person can have a favorite food, and a room can have, say, a favorite person.

richteer commented 9 years ago

The original thought was focused on a particular context, so might not be too hard? Maybe just have it bind to either a whole context, or a subset of certain values... like, maybe a user's favorite food is dependent on which room they are in (example of room+user), etc.

This might rely on changing context to also include the author field as well, which isn't a huge change, just semantic.