Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
stanriders committed Aug 23, 2024
2 parents 1c91eb3 + 5ec4386 commit 24c02fc
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions den0bot/Modules/ModScopeGG.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// den0bot (c) StanR 2024 - MIT License

using System;
using System.Net.Http;
using System.Text.RegularExpressions;
Expand All @@ -21,15 +22,12 @@ public ModScopeGG(ILogger<IModule> logger) : base(logger)
[GeneratedRegex(@"(https:\/\/app\.scope\.gg([\w/]*[\w/])?)")]
private static partial Regex ScopeLinkRegex();

[GeneratedRegex(@"(https:\/\/mediacdn\.allstar\.gg([a-zA-Z0-9/]*[a-zA-Z0-9/])?)")]
[GeneratedRegex(@"(https:\/\/hl\.xplay\.cloud\/video([a-zA-Z0-9/]*[a-zA-Z0-9/])?.mp4)")]
private static partial Regex ClipLinkRegex();

[GeneratedRegex(@"(?>thumbs|og)")]
private static partial Regex ClipLinkReplaceRegex();
[GeneratedRegex(@"""clipTitle"":\s+?""(.+?)"",")]
private static partial Regex ClipTitleCodeRegex();

[GeneratedRegex(@"""clipTitle"":""(.+?)"",")]
private static partial Regex ClipTitleRegex();

public async Task ReceiveMessage(Message message)
{
if (string.IsNullOrEmpty(message.Text))
Expand All @@ -40,14 +38,24 @@ public async Task ReceiveMessage(Message message)
{
using var client = new HttpClient();
var page = await client.GetStringAsync(regexMatch.Value);

var match = ClipLinkRegex().Match(page);
var videoLink = string.Concat(ClipLinkReplaceRegex().Replace(match.Value, "clips"), ".mp4");
var videoLink = match.Value;

if (Uri.TryCreate(videoLink, UriKind.Absolute, out var videoUri))
{
var clipMatch = ClipTitleRegex().Match(page);
var caption = clipMatch.Success ? clipMatch.Groups[1].Value : "VAC";
var clipTitleCodeMatch = ClipTitleCodeRegex().Match(page);
string caption;
if (clipTitleCodeMatch.Success)
{
Regex clipTitleRegex = new Regex(ClipTitlePattern(clipTitleCodeMatch.Groups[1].Value));
var clipTitleMatch = clipTitleRegex.Match(page);
caption = clipTitleMatch.Success ? clipTitleMatch.Groups[1].Value : "VAC";
}
else
{
caption = "VAC";
}

if (!await API.SendVideo(videoLink, message.Chat.Id, caption, message.MessageId))
{
Expand All @@ -64,5 +72,9 @@ public async Task ReceiveMessage(Message message)
}
}

private static string ClipTitlePattern(string clipTitleCode)
{
return @"""" + Regex.Escape(clipTitleCode) + @""":\s+?""(.+?)"",";
}
}
}

0 comments on commit 24c02fc

Please # to comment.