Skip to content

Conversation

@diceguyd30
Copy link
Collaborator

  • Current is not auto granted to the first level
  • Recent commands will log the users as online and supplements the Twitch API
  • Added a random command for when the queue gets to be unwieldy
  • Increased the default queue size to 30 as a long stream can really fill it up with offline levels. At some point we will want to create a system that will boot out the oldest offline level in favor of a recent online one (or something like that).

…is added as the submitter might not stick around and 'current' is immune to the online status check.
quesoqueue.h Outdated
std::deque<Level> _levels;
std::optional<Level> _current;
Twitch _twitch; // query online state
Twitch* _twitch; // query online state
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why switch to pointer? Is there a reason we want to manually manage the lifetime now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make sure that the same instance was being used by both quesoqueue and chat. I'll happily admit that I still don't largely understand how these things work so if switching to a const reference is a better idea, then I'm happy to do it. I just thought that pointers were how objects like this were shared.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same instance. const reference is a pointer that is more idiotproof. It's still getting a pointer under the covers, but this way you can treat it like an object (. notation) and you don't have the ability to accidentally free it early and screw up somewhere else it's being used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

auto user_snapshot = _recent_chatters;
_recent_chatters = {};
for(auto const& [user, last_heard_from] : user_snapshot) {
if (current_time - last_heard_from < std::chrono::minutes(5)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a TODO that this should be runtime-configurable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

for(auto const& [user, last_heard_from] : user_snapshot) {
if (current_time - last_heard_from < std::chrono::minutes(5)) {
online_users.emplace(user);
_recent_chatters.emplace(user, last_heard_from);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it seems like it might be a little extra - do we really need to clean it up? Even a few hundred independent viewers per run isn't so bad in one map.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you can replace these two lines with a call to markAsOnline() too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but this does use a different time than markAsOnline. Also, the first line can't be replaced, only the second.

_timer.Reset();
std::optional<Level> l = _qq.Random();
if (l) {
WriteMessage(std::string("/marker " + l->levelCode + ", submitted by "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this done with a method in Twitch right now? Better not duplicate the code, especially since we know this approach doesn't work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a stub, but the actual code we've tried is here and in Next. I suppose we could leave it out.

return std::nullopt;
}
}
std::vector<Level> new_current = {};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is current in a vector?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's because you're trying to use std::sample. This seems weird, why not just generate an index and not use the extra vector? This leads to weird stuff like "new_current[0]"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, what can I say? I like using these standard functions for things where I can accidentally insert bugs without realizing (https://stackoverflow.com/a/6943003).

nasamuffin
nasamuffin previously approved these changes Nov 24, 2019
@nasamuffin
Copy link
Owner

Hm. No, I didn't mean to approve the whole PR. I just tried to express that the one change didn't have a problem. Friggin Github.

… be added to a list of online users that will supplement Twitch's API. Any user that used a command within the last 5 minutes will be seen as online.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants