Added a few things.
This commit is contained in:
88
Program.cs
88
Program.cs
@@ -5,10 +5,13 @@ using SkyBot;
|
|||||||
|
|
||||||
Env.Load();
|
Env.Load();
|
||||||
|
|
||||||
|
var token = Environment.GetEnvironmentVariable("TOKEN");
|
||||||
|
var channelCache = new Dictionary<long, Channel>();
|
||||||
|
var allowedUserIds = new List<long> { 15652354820931584 };
|
||||||
|
|
||||||
var client = new ValourClient("https://api.valour.gg/");
|
var client = new ValourClient("https://api.valour.gg/");
|
||||||
client.SetupHttpClient();
|
client.SetupHttpClient();
|
||||||
|
|
||||||
var token = Environment.GetEnvironmentVariable("TOKEN");
|
|
||||||
if (string.IsNullOrWhiteSpace(token))
|
if (string.IsNullOrWhiteSpace(token))
|
||||||
{
|
{
|
||||||
Console.WriteLine("TOKEN environment variable not set.");
|
Console.WriteLine("TOKEN environment variable not set.");
|
||||||
@@ -21,11 +24,9 @@ if (!loginResult.Success)
|
|||||||
Console.WriteLine($"Login Failed: {loginResult.Message}");
|
Console.WriteLine($"Login Failed: {loginResult.Message}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})");
|
||||||
|
|
||||||
await client.BotService.JoinAllChannelsAsync();
|
await client.BotService.JoinAllChannelsAsync();
|
||||||
|
|
||||||
var channelCache = new Dictionary<long, Channel>();
|
|
||||||
|
|
||||||
foreach (var planet in client.PlanetService.JoinedPlanets)
|
foreach (var planet in client.PlanetService.JoinedPlanets)
|
||||||
{
|
{
|
||||||
foreach (var channel in planet.Channels)
|
foreach (var channel in planet.Channels)
|
||||||
@@ -35,39 +36,70 @@ foreach (var planet in client.PlanetService.JoinedPlanets)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})");
|
await Utils.UpdateValourUserCountAsync();
|
||||||
|
Utils.StartValourUserUpdater();
|
||||||
var allowedUserIds = new List<long> { 15652354820931584 };
|
|
||||||
|
|
||||||
client.MessageService.MessageReceived += async (message) =>
|
client.MessageService.MessageReceived += async (message) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
string content = message.Content ?? "";
|
string content = message.Content ?? "";
|
||||||
long channelId = message.ChannelId;
|
long channelId = message.ChannelId;
|
||||||
var member = await message.FetchAuthorMemberAsync();
|
var member = await message.FetchAuthorMemberAsync();
|
||||||
|
var pingMember = $"«@m-{member.Id}»";
|
||||||
|
|
||||||
if (content is null) return;
|
if (content is null) return;
|
||||||
|
|
||||||
if (message.AuthorUserId == client.Me.Id) return;
|
if (message.AuthorUserId == client.Me.Id) return;
|
||||||
|
|
||||||
|
|
||||||
if (allowedUserIds.Contains(message.AuthorUserId))
|
if (allowedUserIds.Contains(message.AuthorUserId))
|
||||||
{
|
{
|
||||||
if (Utils.IsSingleEmoji(content))
|
if (Utils.IsSingleEmoji(content))
|
||||||
{
|
{
|
||||||
await message.AddReactionAsync(content);
|
await message.AddReactionAsync(content);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
if (content.StartsWith("/sky echo"))
|
var echoprefixes = new[] { "/sky echo", "s/echo"};
|
||||||
|
if (Utils.ContainsAny(content, echoprefixes))
|
||||||
{
|
{
|
||||||
|
|
||||||
// if (message.AuthorUserId != 15652354820931584) await Utils.SendReplyAsync(channelCache, channelId, "You dont have permission to use this command.");
|
var matchedPrefix = echoprefixes.First(p => content.StartsWith(p, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
var reply = content.Substring(10);
|
var reply = content.Substring(matchedPrefix.Length).TrimStart();
|
||||||
|
|
||||||
if (reply is null) await Utils.SendReplyAsync(channelCache, channelId, $"«@m-{member.Id}» Enter a message to echo.");
|
if (string.IsNullOrWhiteSpace(reply)) await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} Enter a message to echo.");
|
||||||
|
|
||||||
reply = $"«@m-{member.Id}» {reply}";
|
reply = $"{pingMember} {reply}";
|
||||||
|
|
||||||
|
if (reply.Length > 2048)
|
||||||
|
{
|
||||||
|
reply = reply.Substring(0, 2048);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Utils.SendReplyAsync(channelCache, channelId, reply);
|
||||||
|
};
|
||||||
|
|
||||||
|
var echorawprefixes = new[] { "/sky rawecho", "s/rawecho"};
|
||||||
|
if (Utils.ContainsAny(content, echorawprefixes))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (message.AuthorUserId != 15652354820931584)
|
||||||
|
{
|
||||||
|
await Utils.SendReplyAsync(channelCache, channelId, "You do not have permission to execute this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var matchedPrefix = echorawprefixes.First(p => content.StartsWith(p, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
var reply = content.Substring(matchedPrefix.Length).TrimStart();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(reply))
|
||||||
|
{
|
||||||
|
await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} Enter a message to echo.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
reply = $"{reply}";
|
||||||
|
|
||||||
if (reply.Length > 2048)
|
if (reply.Length > 2048)
|
||||||
{
|
{
|
||||||
@@ -79,7 +111,7 @@ client.MessageService.MessageReceived += async (message) =>
|
|||||||
|
|
||||||
if (Utils.ContainsAny(content, "/sky valourroadmap", "s/valourroadmap"))
|
if (Utils.ContainsAny(content, "/sky valourroadmap", "s/valourroadmap"))
|
||||||
{
|
{
|
||||||
await Utils.SendReplyAsync(channelCache, channelId, @$"«@m-{member.Id}» Here is the up-to-date roadmap for Valour:
|
await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember} Here is the up-to-date roadmap for Valour:
|
||||||
~~1. Screen sharing~~
|
~~1. Screen sharing~~
|
||||||
2. Documentation
|
2. Documentation
|
||||||
3. Themes Improvements
|
3. Themes Improvements
|
||||||
@@ -87,21 +119,35 @@ client.MessageService.MessageReceived += async (message) =>
|
|||||||
5. Windows native bugs
|
5. Windows native bugs
|
||||||
6. Tab system bugs
|
6. Tab system bugs
|
||||||
7. Automod/planet moderation");
|
7. Automod/planet moderation");
|
||||||
}
|
};
|
||||||
|
|
||||||
if (Utils.ContainsAny(content, "/sky suggestcommand", "/sky suggestcommands", "/sky suggest", "s/suggestcommand", "s/suggestcommands", "s/suggest"))
|
if (Utils.ContainsAny(content, "/sky suggestcommand", "/sky suggest", "s/suggestcommand", "s/suggest"))
|
||||||
{
|
{
|
||||||
await Utils.SendReplyAsync(channelCache, channelId, $"«@m-{member.Id}» You can suggest a command to be added here: https://docs.google.com/spreadsheets/d/1CzcpLAuMiPL_RODrZ5x25cPj8yE-rR3mEnqrd_2Fbmk");
|
await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} You can suggest a command to be added here: https://docs.google.com/spreadsheets/d/1CzcpLAuMiPL_RODrZ5x25cPj8yE-rR3mEnqrd_2Fbmk");
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Utils.ContainsAny(content, "/sky source", "/sky github", "s/source", "s/github"))
|
if (Utils.ContainsAny(content, "/sky source", "/sky github", "s/source", "s/github"))
|
||||||
{
|
{
|
||||||
await Utils.SendReplyAsync(channelCache, channelId, $"«@m-{member.Id}» You can see my source code here: https://github.com/SkyJoshua/SkyBot");
|
await Utils.SendReplyAsync(channelCache, channelId, $"{pingMember} You can see my source code here: https://github.com/SkyJoshua/SkyBot");
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Utils.ContainsAny(content, "/sky test"))
|
if (Utils.ContainsAny(content, "/sky commands", "/sky cmds", "s/commands", "s/cmds"))
|
||||||
{
|
{
|
||||||
await Utils.SendReplyAsync(channelCache, channelId, "test");
|
await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember} Here is a list of my commands:
|
||||||
|
prefixes can be `/sky` or `s/`
|
||||||
|
`/sky echo <text>`
|
||||||
|
`/sky valourroadmap`
|
||||||
|
`/sky suggest|suggestcommand`
|
||||||
|
`/sky source|github`
|
||||||
|
`/sky commands|cmds`
|
||||||
|
`/sky usercount`");
|
||||||
|
};
|
||||||
|
|
||||||
|
if (Utils.ContainsAny(content, "/sky usercount", "s/usercount"))
|
||||||
|
{
|
||||||
|
await Utils.SendReplyAsync(channelCache, channelId, @$"{pingMember}
|
||||||
|
Current Valour user count is: {Utils.ValourUserCount:N0}
|
||||||
|
You can see a graph of the user count here: /meow");
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
35
utils.cs
35
utils.cs
@@ -1,10 +1,21 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Text.Json;
|
||||||
using Valour.Sdk.Models;
|
using Valour.Sdk.Models;
|
||||||
|
|
||||||
namespace SkyBot
|
namespace SkyBot
|
||||||
{
|
{
|
||||||
public static class Utils
|
public static class Utils
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static readonly HttpClient _http = new HttpClient();
|
||||||
|
private static long _valourUserCount;
|
||||||
|
|
||||||
|
public static long ValourUserCount => _valourUserCount;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static bool IsSingleEmoji(string input)
|
public static bool IsSingleEmoji(string input)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(input))
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
@@ -45,5 +56,29 @@ namespace SkyBot
|
|||||||
Console.WriteLine($"Channel {channel} was not found in the cache.");
|
Console.WriteLine($"Channel {channel} was not found in the cache.");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task UpdateValourUserCountAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await _http.GetStringAsync("https://api.valour.gg/api/users/count");
|
||||||
|
|
||||||
|
_valourUserCount = JsonSerializer.Deserialize<long>(response);
|
||||||
|
|
||||||
|
Console.WriteLine($"Valour user count updated: {_valourUserCount}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Failed to update Valour user count: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StartValourUserUpdater()
|
||||||
|
{
|
||||||
|
var timer = new System.Timers.Timer(300_000);
|
||||||
|
timer.Elapsed += async (_, _) => await UpdateValourUserCountAsync();
|
||||||
|
timer.AutoReset = true;
|
||||||
|
timer.Start();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user