Made it look better ong
This commit is contained in:
96
Program.cs
96
Program.cs
@@ -1,7 +1,7 @@
|
||||
using Valour.Sdk.Client;
|
||||
using Valour.Sdk.Models;
|
||||
using DotNetEnv;
|
||||
using System.Globalization;
|
||||
using SkyBot;
|
||||
|
||||
Env.Load();
|
||||
|
||||
@@ -16,13 +16,14 @@ if (string.IsNullOrWhiteSpace(token))
|
||||
}
|
||||
|
||||
var loginResult = await client.InitializeUser(token);
|
||||
await client.BotService.JoinAllChannelsAsync();
|
||||
if (!loginResult.Success)
|
||||
{
|
||||
Console.WriteLine($"Login Failed: {loginResult.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
await client.BotService.JoinAllChannelsAsync();
|
||||
|
||||
var channelCache = new Dictionary<long, Channel>();
|
||||
|
||||
foreach (var planet in client.PlanetService.JoinedPlanets)
|
||||
@@ -35,6 +36,7 @@ foreach (var planet in client.PlanetService.JoinedPlanets)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})");
|
||||
|
||||
var allowedUserIds = new List<long> { 15652354820931584 };
|
||||
@@ -42,90 +44,68 @@ var allowedUserIds = new List<long> { 15652354820931584 };
|
||||
client.MessageService.MessageReceived += async (message) =>
|
||||
{
|
||||
|
||||
string content = message.Content;
|
||||
string lowerContent = content?.ToLower() ?? "";
|
||||
string content = message.Content ?? "";
|
||||
long channelId = message.ChannelId;
|
||||
var member = await message.FetchAuthorMemberAsync();
|
||||
|
||||
if (content is null) return;
|
||||
|
||||
if (message.AuthorUserId == client.Me.Id) return;
|
||||
|
||||
if (allowedUserIds.Contains(message.AuthorUserId))
|
||||
{
|
||||
if (IsSingleEmoji(message.Content))
|
||||
if (Utils.IsSingleEmoji(content))
|
||||
{
|
||||
await message.AddReactionAsync(message.Content);
|
||||
await message.AddReactionAsync(content);
|
||||
}
|
||||
}
|
||||
|
||||
if (lowerContent.StartsWith("/sky echo "))
|
||||
if (content.StartsWith("/sky echo"))
|
||||
{
|
||||
|
||||
if (message.AuthorUserId != 15652354820931584)
|
||||
// if (message.AuthorUserId != 15652354820931584) await Utils.SendReplyAsync(channelCache, channelId, "You dont have permission to use this command.");
|
||||
|
||||
var reply = content.Substring(10);
|
||||
|
||||
if (reply is null) await Utils.SendReplyAsync(channelCache, channelId, $"«@m-{member.Id}» Enter a message to echo.");
|
||||
|
||||
reply = $"«@m-{member.Id}» {reply}";
|
||||
|
||||
if (reply.Length > 2048)
|
||||
{
|
||||
if (channelCache.TryGetValue(message.ChannelId, out var chan))
|
||||
{
|
||||
await chan.SendMessageAsync("You dont have permission to use this command.");
|
||||
return;
|
||||
}
|
||||
reply = reply.Substring(0, 2048);
|
||||
}
|
||||
|
||||
var reply = message.Content.Substring(10);
|
||||
await Utils.SendReplyAsync(channelCache, channelId, reply);
|
||||
};
|
||||
|
||||
if (channelCache.TryGetValue(message.ChannelId, out var channel))
|
||||
if (Utils.ContainsAny(content, "/sky valourroadmap", "s/valourroadmap"))
|
||||
{
|
||||
await channel.SendMessageAsync(reply);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Channel {message.ChannelId} not found in cache.");
|
||||
}
|
||||
}
|
||||
|
||||
if (lowerContent.Contains("/sky roadmap"))
|
||||
{
|
||||
if (channelCache.TryGetValue(message.ChannelId, out var channel))
|
||||
{
|
||||
var messageText = @"~~1. Screen sharing~~
|
||||
await Utils.SendReplyAsync(channelCache, channelId, @$"«@m-{member.Id}» Here is the up-to-date roadmap for Valour:
|
||||
~~1. Screen sharing~~
|
||||
2. Documentation
|
||||
3. Themes Improvements
|
||||
4. App stores
|
||||
5. Windows native bugs
|
||||
6. Tab system bugs
|
||||
7. Automod/planet moderation";
|
||||
await channel.SendMessageAsync(messageText);
|
||||
}
|
||||
7. Automod/planet moderation");
|
||||
}
|
||||
|
||||
if (lowerContent.Contains("/sky suggestcommands") || lowerContent.Contains("/sky suggestcommand") || lowerContent.Contains("/sky suggest"))
|
||||
if (Utils.ContainsAny(content, "/sky suggestcommand", "/sky suggestcommands", "/sky suggest", "s/suggestcommand", "s/suggestcommands", "s/suggest"))
|
||||
{
|
||||
if (channelCache.TryGetValue(message.ChannelId, out var channel))
|
||||
{
|
||||
await channel.SendMessageAsync("You can suggest a command to be added here: https://docs.google.com/spreadsheets/d/1CzcpLAuMiPL_RODrZ5x25cPj8yE-rR3mEnqrd_2Fbmk");
|
||||
}
|
||||
}
|
||||
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");
|
||||
};
|
||||
|
||||
if (lowerContent.Contains("/sky source") || lowerContent.Contains("/sky github"))
|
||||
if (Utils.ContainsAny(content, "/sky source", "/sky github", "s/source", "s/github"))
|
||||
{
|
||||
if (channelCache.TryGetValue(message.ChannelId, out var channel))
|
||||
await Utils.SendReplyAsync(channelCache, channelId, $"«@m-{member.Id}» You can see my source code here: https://github.com/SkyJoshua/SkyBot");
|
||||
};
|
||||
|
||||
if (Utils.ContainsAny(content, "/sky test"))
|
||||
{
|
||||
await channel.SendMessageAsync("You can see the sourcecode for this bot here: https://github.com/SkyJoshua/SkyBot");
|
||||
}
|
||||
}
|
||||
await Utils.SendReplyAsync(channelCache, channelId, "test");
|
||||
};
|
||||
};
|
||||
|
||||
Console.WriteLine("Listening for messages...");
|
||||
await Task.Delay(Timeout.Infinite);
|
||||
|
||||
static bool IsSingleEmoji(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return false;
|
||||
|
||||
input = input.Trim();
|
||||
|
||||
var enumerator = StringInfo.GetTextElementEnumerator(input);
|
||||
int count = 0;
|
||||
|
||||
while (enumerator.MoveNext())
|
||||
count++;
|
||||
|
||||
return count == 1;
|
||||
}
|
||||
15
SkyBot.csproj
Normal file
15
SkyBot.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNetEnv" Version="3.1.1" />
|
||||
<PackageReference Include="Valour.Sdk" Version="0.5.19" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
49
utils.cs
Normal file
49
utils.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Globalization;
|
||||
using Valour.Sdk.Models;
|
||||
|
||||
namespace SkyBot
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
public static bool IsSingleEmoji(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return false;
|
||||
|
||||
input = input.Trim();
|
||||
|
||||
var enumerator = StringInfo.GetTextElementEnumerator(input);
|
||||
int count = 0;
|
||||
|
||||
while (enumerator.MoveNext())
|
||||
count++;
|
||||
|
||||
return count == 1;
|
||||
}
|
||||
|
||||
public static bool ContainsAny(string input, params string[] values)
|
||||
{
|
||||
var lower = input.ToLower();
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
if (lower.Contains(value.ToLower()))
|
||||
return true;
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static async Task SendReplyAsync(Dictionary<long, Channel> channelCache, long channel, string reply)
|
||||
{
|
||||
if (channelCache.TryGetValue(channel, out var chan))
|
||||
{
|
||||
await chan.SendMessageAsync(reply);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Channel {channel} was not found in the cache.");
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user