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

Youtube voting #1

Open
wants to merge 13 commits into
base: feature/youTubeVotingProvider
Choose a base branch
from

Conversation

teremich
Copy link

@teremich teremich commented Dec 8, 2022

Implemented the voting receiver that uses the Youtube API v1, so it doesn't need an API key.
Requirements for the voting.ini file: VotingReceiver=YoutubeApiV1, YoutubeChannelId, LiveStreamVideoId and the usual stuff.
I think now we can talk to pongo and test this with a more "spammy" chat than the lofigirl stream that I've been using so far.
Also, I dont think the ChaosConfigApp supports the youtube options. Maybe I'll tackle this next

.gitignore Outdated
@@ -28,6 +28,8 @@ dist/bundle.js

# Visual Studio 2015/2017 cache/options directory
.vs/
# Visual Studio Code cache/options directory
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure if we want this in the gitignore. If VS Code is actually used as one of the main editors, configuration should be synced. You may want to add this to the exclude file in the .git directory, which isn't synced (https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files#excluding-local-files-without-creating-a-gitignore-file), or actually integrate the VS Code config into the project. The latter would need to be discussed with pongo.

Copy link
Author

@teremich teremich Dec 22, 2022

Choose a reason for hiding this comment

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

you're right, it's not necessary to to have this here. Thanks for the advice

@@ -75,6 +75,7 @@ public bool RequireBool(string key)

try
{

Copy link
Owner

@Elias-Graf Elias-Graf Dec 22, 2022

Choose a reason for hiding this comment

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

The main changes in this file seem to be newlines. Any reason for those? Is that according to some c# formatting guide? If yes, I'm happy to include them.

Copy link
Author

@teremich teremich Dec 22, 2022

Choose a reason for hiding this comment

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

I think that happened when I tried to resolve a conflict. When I forked your branch this wasn't fixed, so in my original pr I included a insecure quick fix. now that you've taken care of that I didn't have to have touched that file at all.

@@ -5,5 +5,6 @@ enum EVotingReceiver
{
Twitch,
YouTube,
Copy link
Owner

Choose a reason for hiding this comment

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

If this proxy is added, we might want to rename the current (my) implementation to YouTubeV3, but that's not important right now.

buf[index] = (byte)val;
return buf;
}
public static byte[] concat(byte[] one, byte[] two)
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should use LINQ like described in this answer instead of creating a custom implementation https://stackoverflow.com/a/59262/10315665?

Copy link
Author

Choose a reason for hiding this comment

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

VS Code shows me an error when I try to use the Concat method. Maybe I'll just use the overload which takes a list of byte[].

}
return ret;
}
public static byte[] tp(long a, long b, byte[] ary)
Copy link
Owner

Choose a reason for hiding this comment

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

Some more descriptive naming would be nice. Like, I have no idea what tp, or rs is.

Copy link
Author

Choose a reason for hiding this comment

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

I have no idea either. That's why the class is called Magic. As I told you on Discord I copied that "algorithm" from a python library which had the same undescriptive names.


private string build(long[] ts)
{
var b1 = new byte[] { 0x08, 0x00 };
Copy link
Owner

Choose a reason for hiding this comment

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

Technically, doing byte[] b1 = { 0x08, 0x00 }; would save us the new keyword. But I'm not that much of a c# expert to tell what's better.
But I can tell you I've no idea what's going on, lol. I'm assuming this is just copied from somewhere?

Copy link
Author

Choose a reason for hiding this comment

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

Should I make a second pull request after all those change or is there a way to update the current one?

JsonObject responseData = res["continuationContents"]!["liveChatContinuation"]!.AsObject();
var continuations = responseData!["continuations"]!.AsArray()![0]!.AsObject();
JsonNode? continuationData;
if (continuations.TryGetPropertyValue("invalidationContinuationData", out continuationData))
Copy link
Owner

@Elias-Graf Elias-Graf Dec 22, 2022

Choose a reason for hiding this comment

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

One shouldn't use the null-forgiving operator. Since it's technically an arbitrary JSON object, all fields could potentially be null. So you should probably use the ? (null conditional), and check afterwords if the value exists. Maybe you could even chain the call? Like:

continuations.TryGetPropertyValue("invalidationContinuationData")
  .?["continuation"]
  .?GetValue<string>();

But I'm not sure, since the API uses that weird out thing (which is of course not your fault lol).

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, and btw. the upstream is using some other JSON parsing thing. Although, I haven't been able to merge that yet, since the c++ part keeps crashing on me :(. But maybe we could use the same library? Looks pretty clean: gta-chaos-mod@b2c9732#diff-19156a6e6f3132fe9e2de63a68a651114269e429e04a09898a88d5fb8af64bdcL1-R171.

@Elias-Graf
Copy link
Owner

Your coding style, using early returns instead of nested ifs, is pretty nice btw :). Easier to read this way.

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.

2 participants