Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContextModule #4

Open
richteer opened this issue Sep 11, 2015 · 2 comments
Open

ContextModule #4

richteer opened this issue Sep 11, 2015 · 2 comments
Labels

Comments

@richteer
Copy link
Contributor

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.

@richteer richteer added the RFC label Sep 11, 2015
@sjrct
Copy link
Member

sjrct commented Oct 6, 2015

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
Copy link
Contributor Author

richteer commented Oct 6, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants