-
Notifications
You must be signed in to change notification settings - Fork 36
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
What interface would we ideally want to expose for library users? #43
Comments
So my initial idea was to do all this via SEChatWrapper, by extending the system we have now and adding methods as we go along. But if we want a full API, this is probably necessary. I like your current template. Will things like |
Yeah, I don't want to get too far ahead of myself, get too distracted by nice ideas, and lose focus on making the simple things actually work. But it's nice to have some idea of what we could provide later. What you suggest is probably ideal: loading attributes lazily by default, with an option to fetch the data immediately. Another possible interface for that behaviour would be to have a room = chat.get_room(1234, access=True) # all data explicitly requested
room = chat.get_room(1234).loaded() # all data explicitly requested
room = chat.get_room(1234)
room.room_name # room_name data implicitly requested If it's exposed as a method instead of a parameter, users could request that an room's data be fetched at any point, not just at the point where they first retrieve the room object (small win). This also simplifies things if there are multiple ways to get room objects (bigger win): For example, say we have a for room in user.owned_rooms():
if room.room_id == 1:
# we expect to be active in this room for some reason, so let's preload!
room.loaded() It would probably be reasonable to cache all user and room data during a session, so if you do That is, we ignore the possibility that room or user data changes after we initially get it. Later on, it might be nice to have some kind of automatic cache invalidation, so that the objects are automatically updated when you access a field that hasn't been reloaded in a few hours, but that's probably not a key feature. |
Re: method vs parameter - we can just use an My idea was like this, internally for each object, we have a bunch of lazy getter groups. For The object stores a list of which groups have been loaded. If I ask for |
Basically, I envision something like this:
|
Yeah, something like that sounds good. I was just thinking that it would be nice to also have a synchronous way of consuming messages, rather than necessarily using a callback. Maybe if you do This might not be the easiest interface for a complicated bot (although you could have multiple watchers running from different threads if you wanted to), but for simple bots it could be convenient. import chatexchange
chat = chatexchange.connect( # class ChatConnection
'chat.stackexchange.com', 'j@jeremybanks.ca', 'password')
sandbox = chat.get_room(14219)
# context manager support to automatically close watcher when we're done with it
with sandbox.watch() as watcher:
# an iterator over new messages - locked to ensure only one consumer
for event in watcher.new_events():
if event.type != event.Types.message_posted:
continue
message = event.message
if message.text_body == "hello bot":
charcoal_sandbox.send("thank you; goodbye user")
break
else:
message.reply("please say `hello bot`") If you call |
This seems doable. Not a priority (of course, feel free to implement it!), but it looks more pythony :) |
Moves some logic from client to room. Adds simple docstrings with epydoc annotations to public fields and methods of Client. Also adds epydoc as a dev dependency, and adds `make epydocs`. It probably isn't necessary to add this documentation to our internal methods, and I won't bother with browser for now, but I think it's useful to have for our user-friendly interface. (Both for users directly and through IDEs that recognize the type annotations, like PyCharm CE.) resolves #52 - let's forget about slugs and message sets for now. We can reply to messages and a weak set of current messages might be pointless. ref #65, #43 - event/message iterators/contexts are still outstanding.
Moves some logic from client to room. Adds simple docstrings with epydoc annotations to public fields and methods of Client. Also adds epydoc as a dev dependency, and adds `make epydocs`. It probably isn't necessary to add this documentation to our internal methods, and I won't bother with browser for now, but I think it's useful to have for our user-friendly interface. (Both for users directly and through IDEs that recognize the type annotations, like PyCharm CE.) resolves #52 - let's forget about slugs and message sets for now. We can reply to messages and a weak set of current messages might be pointless. ref #65, #43 - event/message iterators/contexts are still outstanding.
Without thinking too much about the details of the implementation, I'm wonder what kind of interface would be nicest to expose to users of the library. I'm currently imagining something like:
Let me know if you have any thoughts.
The text was updated successfully, but these errors were encountered: