Updated Utility module
This commit is contained in:
parent
0787490aea
commit
f2618793b3
4 changed files with 71 additions and 36 deletions
|
@ -251,7 +251,7 @@ public sealed class AiAssistantService
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
await _cbs.RunChatterBot(sg, msg, channel, sess, query);
|
await _cbs.RunChatterBot(sg, msg, channel, sess, query);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandString = GetCommandString(model);
|
var commandString = GetCommandString(model);
|
||||||
|
|
|
@ -9,7 +9,7 @@ public sealed class CommandPromptResultModel
|
||||||
|
|
||||||
[JsonPropertyName("arguments")]
|
[JsonPropertyName("arguments")]
|
||||||
public Dictionary<string, string> Arguments { get; set; } = new();
|
public Dictionary<string, string> Arguments { get; set; } = new();
|
||||||
|
|
||||||
[JsonPropertyName("remaining")]
|
[JsonPropertyName("remaining")]
|
||||||
[JsonConverter(typeof(NumberToStringConverter))]
|
[JsonConverter(typeof(NumberToStringConverter))]
|
||||||
public string Remaining { get; set; } = string.Empty;
|
public string Remaining { get; set; } = string.Empty;
|
||||||
|
|
|
@ -8,7 +8,7 @@ public partial class Utility
|
||||||
private readonly IEnumerable<IConfigService> _settingServices;
|
private readonly IEnumerable<IConfigService> _settingServices;
|
||||||
|
|
||||||
public ConfigCommands(IEnumerable<IConfigService> settingServices)
|
public ConfigCommands(IEnumerable<IConfigService> settingServices)
|
||||||
=> _settingServices = settingServices.Where(x => x.Name != "medusa");
|
=> _settingServices = settingServices.Where(x => x.Name != "marmalade");
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
|
|
|
@ -459,47 +459,82 @@ public partial class Utility : EllieModule
|
||||||
public async Task StickerAdd(string name = null, string description = null, params string[] tags)
|
public async Task StickerAdd(string name = null, string description = null, params string[] tags)
|
||||||
{
|
{
|
||||||
string format;
|
string format;
|
||||||
Stream stream;
|
Stream stream = null;
|
||||||
|
|
||||||
if (ctx.Message.Stickers.Count is 1 && ctx.Message.Stickers.First() is SocketSticker ss)
|
|
||||||
{
|
|
||||||
name ??= ss.Name;
|
|
||||||
description = ss.Description;
|
|
||||||
tags = tags is null or { Length: 0 } ? ss.Tags.ToArray() : tags;
|
|
||||||
format = FormatToExtension(ss.Format);
|
|
||||||
|
|
||||||
using var http = _httpFactory.CreateClient();
|
|
||||||
stream = await http.GetStreamAsync(ss.GetStickerUrl());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await Response().Error(strs.sticker_error).SendAsync();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (tags.Length == 0)
|
if (ctx.Message.Stickers.Count is 1 && ctx.Message.Stickers.First() is SocketSticker ss)
|
||||||
tags = [name];
|
{
|
||||||
|
name ??= ss.Name;
|
||||||
|
description = ss.Description;
|
||||||
|
tags = tags is null or { Length: 0 } ? ss.Tags.ToArray() : tags;
|
||||||
|
format = FormatToExtension(ss.Format);
|
||||||
|
|
||||||
await ctx.Guild.CreateStickerAsync(
|
using var http = _httpFactory.CreateClient();
|
||||||
name,
|
stream = await http.GetStreamAsync(ss.GetStickerUrl());
|
||||||
stream,
|
}
|
||||||
$"{name}.{format}",
|
else if (ctx.Message.Attachments.Count is 1 && name is not null)
|
||||||
tags,
|
{
|
||||||
string.IsNullOrWhiteSpace(description) ? "Missing description" : description
|
if (tags.Length == 0)
|
||||||
);
|
tags = [name];
|
||||||
|
|
||||||
await ctx.OkAsync();
|
if (ctx.Message.Attachments.Count != 1)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
{
|
return;
|
||||||
Log.Warning(ex, "Error occurred while adding a sticker: {Message}", ex.Message);
|
}
|
||||||
await Response().Error(strs.error_occured).SendAsync();
|
|
||||||
|
var attach = ctx.Message.Attachments.First();
|
||||||
|
|
||||||
|
|
||||||
|
if (attach.Size > 512_000 || attach.Width != 300 || attach.Height != 300)
|
||||||
|
{
|
||||||
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
format = attach.Filename
|
||||||
|
.Split('.')
|
||||||
|
.Last()
|
||||||
|
.ToLowerInvariant();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(format) || (format != "png" && format != "apng"))
|
||||||
|
{
|
||||||
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var http = _httpFactory.CreateClient();
|
||||||
|
stream = await http.GetStreamAsync(attach.Url);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Response().Error(strs.sticker_error).SendAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ctx.Guild.CreateStickerAsync(
|
||||||
|
name,
|
||||||
|
stream,
|
||||||
|
$"{name}.{format}",
|
||||||
|
tags,
|
||||||
|
string.IsNullOrWhiteSpace(description) ? "Missing description" : description
|
||||||
|
);
|
||||||
|
|
||||||
|
await ctx.OkAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
(Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warning(ex, "Error occurred while adding a sticker: {Message}", ex.Message);
|
||||||
|
await Response().Error(strs.error_occured).SendAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
await stream.DisposeAsync();
|
await (stream?.DisposeAsync() ?? ValueTask.CompletedTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue