final github release
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using SkyBot.Helpers;
|
|
||||||
using SkyBot.Models;
|
using SkyBot.Models;
|
||||||
|
using Valour.Sdk.Client;
|
||||||
using Valour.Sdk.Models;
|
using Valour.Sdk.Models;
|
||||||
|
|
||||||
namespace SkyBot.Commands
|
namespace SkyBot.Commands
|
||||||
@@ -15,8 +15,13 @@ namespace SkyBot.Commands
|
|||||||
|
|
||||||
public async Task Execute(CommandContext ctx)
|
public async Task Execute(CommandContext ctx)
|
||||||
{
|
{
|
||||||
|
ValourClient Client = ctx.Client;
|
||||||
ConcurrentDictionary<long, Channel> channelCache = ctx.ChannelCache;
|
ConcurrentDictionary<long, Channel> channelCache = ctx.ChannelCache;
|
||||||
|
PlanetMember Member = ctx.Member;
|
||||||
|
Message Message = ctx.Message;
|
||||||
|
Planet Planet = ctx.Planet;
|
||||||
long channelId = ctx.ChannelId;
|
long channelId = ctx.ChannelId;
|
||||||
|
string[] Args = ctx.Args;
|
||||||
|
|
||||||
if (!channelCache.TryGetValue(channelId, out var channel)) return;
|
if (!channelCache.TryGetValue(channelId, out var channel)) return;
|
||||||
|
|
||||||
|
|||||||
72
SkyBot/Commands/Dev/React.cs
Normal file
72
SkyBot/Commands/Dev/React.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
using SkyBot.Helpers;
|
||||||
|
using SkyBot.Models;
|
||||||
|
using Valour.Sdk.Models;
|
||||||
|
using Valour.Shared.Models;
|
||||||
|
|
||||||
|
namespace SkyBot.Commands
|
||||||
|
{
|
||||||
|
public class React : ICommand
|
||||||
|
{
|
||||||
|
public string Name => "react";
|
||||||
|
public string[] Aliases => [];
|
||||||
|
public string Description => "Send a message with a reaction at a set count.";
|
||||||
|
public string Section => "Dev";
|
||||||
|
public string Usage => "react <emoji> <amount> <message>";
|
||||||
|
|
||||||
|
public async Task Execute(CommandContext ctx)
|
||||||
|
{
|
||||||
|
ConcurrentDictionary<long, Channel> channelCache = ctx.ChannelCache;
|
||||||
|
long channelId = ctx.ChannelId;
|
||||||
|
|
||||||
|
if (!channelCache.TryGetValue(channelId, out var channel)) return;
|
||||||
|
|
||||||
|
if (!PermissionHelper.IsOwner(ctx.Member))
|
||||||
|
{
|
||||||
|
await MessageHelper.ReplyAsync(ctx, channel, "This is a Dev only command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] args = ctx.Args;
|
||||||
|
|
||||||
|
if (args.Length < 3)
|
||||||
|
{
|
||||||
|
await MessageHelper.ReplyAsync(ctx, channel, $"Usage: `{Config.Prefix}react <emoji> <amount> <message>`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string emoji = args[0];
|
||||||
|
|
||||||
|
if (!int.TryParse(args[1], out int amount) || amount < 1)
|
||||||
|
{
|
||||||
|
await MessageHelper.ReplyAsync(ctx, channel, "Amount must be a number between 1 and 100.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string content = string.Join(" ", args.Skip(2));
|
||||||
|
|
||||||
|
var reactions = Enumerable.Range(0, amount)
|
||||||
|
.Select(_ => new MessageReaction
|
||||||
|
{
|
||||||
|
Emoji = emoji,
|
||||||
|
AuthorUserId = ctx.Client.Me.Id,
|
||||||
|
AuthorMemberId = ctx.Planet.MyMember?.Id,
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var msg = new Message(ctx.Client)
|
||||||
|
{
|
||||||
|
Content = content,
|
||||||
|
ChannelId = channelId,
|
||||||
|
PlanetId = ctx.Planet.Id,
|
||||||
|
AuthorUserId = ctx.Client.Me.Id,
|
||||||
|
AuthorMemberId = ctx.Planet.MyMember?.Id,
|
||||||
|
Reactions = reactions,
|
||||||
|
Fingerprint = Guid.NewGuid().ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
await ctx.Client.MessageService.SendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,7 @@ namespace SkyBot.Commands
|
|||||||
if (!channelCache.TryGetValue(channelId, out var channel)) return;
|
if (!channelCache.TryGetValue(channelId, out var channel)) return;
|
||||||
|
|
||||||
string msg = @"Here is a link to a Bot Guide that SkyJoshua has made (WIP):
|
string msg = @"Here is a link to a Bot Guide that SkyJoshua has made (WIP):
|
||||||
https://github.com/SkyJoshua/Valour-Bot-Guide";
|
https://git.skyjoshua.xyz/SkyJoshua/Valour-Bot-Guide";
|
||||||
|
|
||||||
await MessageHelper.ReplyAsync(ctx, channel, msg);
|
await MessageHelper.ReplyAsync(ctx, channel, msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,5 @@ namespace SkyBot
|
|||||||
public static readonly long OwnerId = 15652354820931584;
|
public static readonly long OwnerId = 15652354820931584;
|
||||||
public static readonly string Prefix = "s/";
|
public static readonly string Prefix = "s/";
|
||||||
public static readonly string SourceLink = "https://github.com/SkyJoshua/SkyBot";
|
public static readonly string SourceLink = "https://github.com/SkyJoshua/SkyBot";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Globalization;
|
||||||
using SkyBot.Models;
|
using SkyBot.Models;
|
||||||
using Valour.Sdk.Models;
|
using Valour.Sdk.Models;
|
||||||
using Valour.Shared;
|
using Valour.Shared;
|
||||||
@@ -10,6 +11,7 @@ namespace SkyBot.Helpers
|
|||||||
public static string Mention(this PlanetMember member) => $"«@m-{member.Id}»";
|
public static string Mention(this PlanetMember member) => $"«@m-{member.Id}»";
|
||||||
public static string Mention(this User user) => $"«@u-{user.Id}»";
|
public static string Mention(this User user) => $"«@u-{user.Id}»";
|
||||||
public static string ToTitleCase(this string str) => System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str);
|
public static string ToTitleCase(this string str) => System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str);
|
||||||
|
|
||||||
public static async Task<TaskResult<Message>> ReplyAsync(CommandContext ctx, Channel channel, string content)
|
public static async Task<TaskResult<Message>> ReplyAsync(CommandContext ctx, Channel channel, string content)
|
||||||
{
|
{
|
||||||
long? replyToId = ctx.Message.ReplyToId.HasValue ? ctx.Message.ReplyToId : ctx.Message.Id;
|
long? replyToId = ctx.Message.ReplyToId.HasValue ? ctx.Message.ReplyToId : ctx.Message.Id;
|
||||||
@@ -26,11 +28,13 @@ namespace SkyBot.Helpers
|
|||||||
};
|
};
|
||||||
return await ctx.Client.MessageService.SendMessage(msg);
|
return await ctx.Client.MessageService.SendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<TaskResult<Message>> EditAsync(Channel channel, Message message, string content)
|
public static async Task<TaskResult<Message>> EditAsync(Channel channel, Message message, string content)
|
||||||
{
|
{
|
||||||
message.Content = content;
|
message.Content = content;
|
||||||
return await channel.Planet.Node.PutAsyncWithResponse<Message>($"api/messages/{message.Id}", message);
|
return await channel.Planet.Node.PutAsyncWithResponse<Message>($"api/messages/{message.Id}", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DateTime? ParseDuration(string input)
|
public static DateTime? ParseDuration(string input)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(input)) return null;
|
if (string.IsNullOrWhiteSpace(input)) return null;
|
||||||
@@ -49,5 +53,19 @@ namespace SkyBot.Helpers
|
|||||||
_ => null
|
_ => null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ namespace SkyBot.Helpers
|
|||||||
private static readonly HttpClient _http = new HttpClient();
|
private static readonly HttpClient _http = new HttpClient();
|
||||||
private static long _valourUsercount;
|
private static long _valourUsercount;
|
||||||
public static long ValourUsercount => _valourUsercount;
|
public static long ValourUsercount => _valourUsercount;
|
||||||
|
|
||||||
public static async Task UpdateUsercount()
|
public static async Task UpdateUsercount()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -23,16 +23,13 @@ namespace SkyBot.Services.Messages
|
|||||||
string prefix = Config.Prefix;
|
string prefix = Config.Prefix;
|
||||||
string content = message.Content ?? "";
|
string content = message.Content ?? "";
|
||||||
if (string.IsNullOrWhiteSpace(content)) return;
|
if (string.IsNullOrWhiteSpace(content)) return;
|
||||||
if (!content.ToLower().StartsWith(prefix)) return;
|
|
||||||
|
|
||||||
long channelId = message.ChannelId;
|
long channelId = message.ChannelId;
|
||||||
PlanetMember member = await message.FetchAuthorMemberAsync();
|
PlanetMember member = await message.FetchAuthorMemberAsync();
|
||||||
|
noPrefixMessages(message, content);
|
||||||
var parts = content.Substring(prefix.Length).Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
var parts = content.Substring(prefix.Length).Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (parts.Length == 0) return;
|
if (parts.Length == 0) return;
|
||||||
|
|
||||||
string command = parts[0].ToLower();
|
string command = parts[0].ToLower();
|
||||||
string[] args = parts[1..];
|
string[] args = parts[1..];
|
||||||
|
|
||||||
CommandContext ctx = new CommandContext
|
CommandContext ctx = new CommandContext
|
||||||
{
|
{
|
||||||
ChannelCache = channelCache,
|
ChannelCache = channelCache,
|
||||||
@@ -44,6 +41,21 @@ namespace SkyBot.Services.Messages
|
|||||||
Client = client
|
Client = client
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async void noPrefixMessages(Message message, string content)
|
||||||
|
{
|
||||||
|
if (message.AuthorUserId == Config.OwnerId)
|
||||||
|
{
|
||||||
|
if (MessageHelper.IsSingleEmoji(content))
|
||||||
|
{
|
||||||
|
await message.AddReactionAsync(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// await message.AddReactionAsync("🫃");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!content.ToLower().StartsWith(prefix)) return;
|
||||||
if (_cooldowns.TryGetValue(message.AuthorUserId, out var lastUsed) && DateTime.UtcNow - lastUsed < _cooldown)
|
if (_cooldowns.TryGetValue(message.AuthorUserId, out var lastUsed) && DateTime.UtcNow - lastUsed < _cooldown)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user