mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 10:18:27 -04:00
.btr and .sclr added, cleanup
This commit is contained in:
@@ -164,8 +164,8 @@ public sealed class AiAssistantService
|
||||
funcs.Add(new()
|
||||
{
|
||||
Name = cmd,
|
||||
Desc = commandStrings?.Desc?.Replace("currency", "flowers") ?? string.Empty,
|
||||
Params = commandStrings?.Params.FirstOrDefault()
|
||||
Desc = commandStrings.Desc?.Replace("currency", "flowers") ?? string.Empty,
|
||||
Params = commandStrings.Params.FirstOrDefault()
|
||||
?.Select(x => new AiCommandParamModel()
|
||||
{
|
||||
Desc = x.Value.Desc,
|
||||
@@ -219,6 +219,9 @@ public sealed class AiAssistantService
|
||||
ITextChannel channel,
|
||||
string query)
|
||||
{
|
||||
if (guild is not SocketGuild sg)
|
||||
return false;
|
||||
|
||||
// check permissions
|
||||
var pcResult = await _permChecker.CheckPermsAsync(
|
||||
guild,
|
||||
@@ -239,9 +242,6 @@ public sealed class AiAssistantService
|
||||
{
|
||||
if (model.Name == ".ai_chat")
|
||||
{
|
||||
if (guild is not SocketGuild sg)
|
||||
return false;
|
||||
|
||||
var sess = _cbs.GetOrCreateSession(guild.Id);
|
||||
if (sess is null)
|
||||
return false;
|
||||
@@ -253,7 +253,7 @@ public sealed class AiAssistantService
|
||||
var commandString = GetCommandString(model);
|
||||
|
||||
var msgTask = _sender.Response(channel)
|
||||
.Embed(_sender.CreateEmbed()
|
||||
.Embed(_sender.CreateEmbed(guild?.Id)
|
||||
.WithOkColor()
|
||||
.WithAuthor(msg.Author.GlobalName,
|
||||
msg.Author.RealAvatarUrl().ToString())
|
||||
@@ -261,8 +261,7 @@ public sealed class AiAssistantService
|
||||
.SendAsync();
|
||||
|
||||
|
||||
await _cmdHandler.TryRunCommand(
|
||||
(SocketGuild)guild,
|
||||
await _cmdHandler.TryRunCommand(sg,
|
||||
(ISocketMessageChannel)channel,
|
||||
new DoAsUserMessage((SocketUserMessage)msg, msg.Author, commandString));
|
||||
|
||||
@@ -298,7 +297,7 @@ public sealed class AiAssistantService
|
||||
await _sender.Response(channel)
|
||||
.Error(errorMsg)
|
||||
.SendAsync();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@ public sealed class AiCommandModel
|
||||
public required string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("desc")]
|
||||
public required string Desc { get; set; }
|
||||
public required string? Desc { get; set; }
|
||||
|
||||
[JsonPropertyName("params")]
|
||||
public required IReadOnlyList<AiCommandParamModel> Params { get; set; }
|
||||
|
@@ -127,7 +127,7 @@ public partial class Utility
|
||||
.CurrentPage(page)
|
||||
.Page((items, _) =>
|
||||
{
|
||||
return _sender.CreateEmbed()
|
||||
return CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.alias_list))
|
||||
.WithDescription(string.Join("\n", items.Select(x => $"`{x.Key}` => `{x.Value}`")));
|
||||
|
@@ -20,7 +20,7 @@ public partial class Utility
|
||||
if (setting is null)
|
||||
{
|
||||
var configNames = _settingServices.Select(x => x.Name);
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.WithErrorColor()
|
||||
.WithDescription(GetText(strs.config_not_found(Format.Code(name))))
|
||||
.AddField(GetText(strs.config_list), string.Join("\n", configNames));
|
||||
@@ -43,7 +43,7 @@ public partial class Utility
|
||||
name = name?.ToLowerInvariant();
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.config_list))
|
||||
.WithDescription(string.Join("\n", configNames));
|
||||
@@ -58,7 +58,7 @@ public partial class Utility
|
||||
// if config name is not found, print error and the list of configs
|
||||
if (setting is null)
|
||||
{
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.WithErrorColor()
|
||||
.WithDescription(GetText(strs.config_not_found(Format.Code(name))))
|
||||
.AddField(GetText(strs.config_list), string.Join("\n", configNames));
|
||||
@@ -75,7 +75,7 @@ public partial class Utility
|
||||
if (string.IsNullOrWhiteSpace(prop))
|
||||
{
|
||||
var propStrings = GetPropsAndValuesString(setting, propNames);
|
||||
var embed = _sender.CreateEmbed().WithOkColor().WithTitle($"⚙️ {setting.Name}").WithDescription(propStrings);
|
||||
var embed = CreateEmbed().WithOkColor().WithTitle($"⚙️ {setting.Name}").WithDescription(propStrings);
|
||||
|
||||
|
||||
await Response().Embed(embed).SendAsync();
|
||||
@@ -88,7 +88,7 @@ public partial class Utility
|
||||
if (!exists)
|
||||
{
|
||||
var propStrings = GetPropsAndValuesString(setting, propNames);
|
||||
var propErrorEmbed = _sender.CreateEmbed()
|
||||
var propErrorEmbed = CreateEmbed()
|
||||
.WithErrorColor()
|
||||
.WithDescription(GetText(
|
||||
strs.config_prop_not_found(Format.Code(prop), Format.Code(name))))
|
||||
@@ -110,7 +110,7 @@ public partial class Utility
|
||||
if (prop != "currency.sign")
|
||||
value = Format.Code(Format.Sanitize(value.TrimTo(1000)), "json");
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.AddField("Config", Format.Code(setting.Name), true)
|
||||
.AddField("Prop", Format.Code(prop), true)
|
||||
|
@@ -17,7 +17,7 @@ public partial class Utility
|
||||
return;
|
||||
}
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithPendingColor()
|
||||
.WithTitle(GetText(strs.giveaway_starting))
|
||||
.WithDescription(message);
|
||||
@@ -103,7 +103,7 @@ public partial class Utility
|
||||
return;
|
||||
}
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithTitle(GetText(strs.giveaway_list))
|
||||
.WithOkColor();
|
||||
|
||||
|
@@ -20,8 +20,14 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
private SortedSet<GiveawayModel> _giveawayCache = new SortedSet<GiveawayModel>();
|
||||
private readonly NadekoRandom _rng;
|
||||
|
||||
public GiveawayService(DbService db, IBotCreds creds, DiscordSocketClient client,
|
||||
IMessageSenderService sender, IBotStrings strings, ILocalization localization, IMemoryCache cache)
|
||||
public GiveawayService(
|
||||
DbService db,
|
||||
IBotCreds creds,
|
||||
DiscordSocketClient client,
|
||||
IMessageSenderService sender,
|
||||
IBotStrings strings,
|
||||
ILocalization localization,
|
||||
IMemoryCache cache)
|
||||
{
|
||||
_db = db;
|
||||
_creds = creds;
|
||||
@@ -37,7 +43,8 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
_client.ReactionRemoved += OnReactionRemoved;
|
||||
}
|
||||
|
||||
private async Task OnReactionRemoved(Cacheable<IUserMessage, ulong> msg,
|
||||
private async Task OnReactionRemoved(
|
||||
Cacheable<IUserMessage, ulong> msg,
|
||||
Cacheable<IMessageChannel, ulong> arg2,
|
||||
SocketReaction r)
|
||||
{
|
||||
@@ -55,7 +62,9 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnReactionAdded(Cacheable<IUserMessage, ulong> msg, Cacheable<IMessageChannel, ulong> ch,
|
||||
private async Task OnReactionAdded(
|
||||
Cacheable<IUserMessage, ulong> msg,
|
||||
Cacheable<IMessageChannel, ulong> ch,
|
||||
SocketReaction r)
|
||||
{
|
||||
if (!r.User.IsSpecified)
|
||||
@@ -84,9 +93,9 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var gas = await ctx
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => Linq2DbExpressions.GuildOnShard(x.GuildId, _creds.TotalShards, _client.ShardId))
|
||||
.ToArrayAsync();
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => Linq2DbExpressions.GuildOnShard(x.GuildId, _creds.TotalShards, _client.ShardId))
|
||||
.ToArrayAsync();
|
||||
|
||||
lock (_giveawayCache)
|
||||
{
|
||||
@@ -101,8 +110,8 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
lock (_giveawayCache)
|
||||
{
|
||||
toEnd = _giveawayCache.TakeWhile(
|
||||
x => x.EndsAt <= DateTime.UtcNow.AddSeconds(15))
|
||||
.ToArray();
|
||||
x => x.EndsAt <= DateTime.UtcNow.AddSeconds(15))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
foreach (var ga in toEnd)
|
||||
@@ -119,29 +128,33 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int?> StartGiveawayAsync(ulong guildId, ulong channelId, ulong messageId, TimeSpan duration,
|
||||
public async Task<int?> StartGiveawayAsync(
|
||||
ulong guildId,
|
||||
ulong channelId,
|
||||
ulong messageId,
|
||||
TimeSpan duration,
|
||||
string message)
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
// first check if there are more than 5 giveaways
|
||||
var count = await ctx
|
||||
.GetTable<GiveawayModel>()
|
||||
.CountAsync(x => x.GuildId == guildId);
|
||||
.GetTable<GiveawayModel>()
|
||||
.CountAsync(x => x.GuildId == guildId);
|
||||
|
||||
if (count >= 5)
|
||||
return null;
|
||||
|
||||
var endsAt = DateTime.UtcNow + duration;
|
||||
var ga = await ctx.GetTable<GiveawayModel>()
|
||||
.InsertWithOutputAsync(() => new GiveawayModel
|
||||
{
|
||||
GuildId = guildId,
|
||||
MessageId = messageId,
|
||||
ChannelId = channelId,
|
||||
Message = message,
|
||||
EndsAt = endsAt,
|
||||
});
|
||||
.InsertWithOutputAsync(() => new GiveawayModel
|
||||
{
|
||||
GuildId = guildId,
|
||||
MessageId = messageId,
|
||||
ChannelId = channelId,
|
||||
Message = message,
|
||||
EndsAt = endsAt,
|
||||
});
|
||||
|
||||
lock (_giveawayCache)
|
||||
{
|
||||
@@ -157,18 +170,18 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var giveaway = await ctx
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.GuildId == guildId && x.Id == id)
|
||||
.LoadWith(x => x.Participants)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.GuildId == guildId && x.Id == id)
|
||||
.LoadWith(x => x.Participants)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
|
||||
if (giveaway is null)
|
||||
return false;
|
||||
|
||||
await ctx
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.Id == id)
|
||||
.DeleteAsync();
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.Id == id)
|
||||
.DeleteAsync();
|
||||
|
||||
lock (_giveawayCache)
|
||||
{
|
||||
@@ -222,9 +235,9 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var ga = await ctx
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.GuildId == guildId && x.Id == id)
|
||||
.DeleteWithOutputAsync();
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.GuildId == guildId && x.Id == id)
|
||||
.DeleteWithOutputAsync();
|
||||
|
||||
if (ga is not { Length: > 0 })
|
||||
return false;
|
||||
@@ -242,9 +255,9 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
return await ctx
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.ToListAsync();
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> JoinGivawayAsync(ulong messageId, ulong userId, string userName)
|
||||
@@ -252,23 +265,23 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var giveaway = await ctx
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.MessageId == messageId)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.MessageId == messageId)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
|
||||
if (giveaway is null)
|
||||
return false;
|
||||
|
||||
// add the user to the database
|
||||
await ctx.GetTable<GiveawayUser>()
|
||||
.InsertAsync(
|
||||
() => new GiveawayUser()
|
||||
{
|
||||
UserId = userId,
|
||||
GiveawayId = giveaway.Id,
|
||||
Name = userName,
|
||||
}
|
||||
);
|
||||
.InsertAsync(
|
||||
() => new GiveawayUser()
|
||||
{
|
||||
UserId = userId,
|
||||
GiveawayId = giveaway.Id,
|
||||
Name = userName,
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -278,17 +291,17 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var giveaway = await ctx
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.MessageId == messageId)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
.GetTable<GiveawayModel>()
|
||||
.Where(x => x.MessageId == messageId)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
|
||||
if (giveaway is null)
|
||||
return false;
|
||||
|
||||
await ctx
|
||||
.GetTable<GiveawayUser>()
|
||||
.Where(x => x.UserId == userId && x.GiveawayId == giveaway.Id)
|
||||
.DeleteAsync();
|
||||
.GetTable<GiveawayUser>()
|
||||
.Where(x => x.UserId == userId && x.GiveawayId == giveaway.Id)
|
||||
.DeleteAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -316,14 +329,14 @@ public sealed class GiveawayService : INService, IReadyExecutor
|
||||
{Format.Code(winner.UserId.ToString())}
|
||||
""";
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.giveaway_ended))
|
||||
.WithDescription(ga.Message)
|
||||
.WithFooter($"id: {new kwum(ga.Id).ToString()}")
|
||||
.AddField(GetText(strs.winner),
|
||||
winnerStr,
|
||||
true);
|
||||
var eb = _sender.CreateEmbed(ch.GuildId)
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.giveaway_ended))
|
||||
.WithDescription(ga.Message)
|
||||
.WithFooter($"id: {new kwum(ga.Id).ToString()}")
|
||||
.AddField(GetText(strs.winner),
|
||||
winnerStr,
|
||||
true);
|
||||
|
||||
try
|
||||
{
|
||||
|
@@ -1,39 +1,66 @@
|
||||
using NadekoBot.Db.Models;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace NadekoBot.Modules.Utility;
|
||||
|
||||
public interface IGuildColorsService
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public sealed class GuildColorsService : IGuildColorsService, INService
|
||||
{
|
||||
private readonly DbService _db;
|
||||
|
||||
public GuildColorsService(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task<GuildColors?> GetGuildColors(ulong guildId)
|
||||
{
|
||||
// get from database and cache it with linq2db
|
||||
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
return null;
|
||||
// return await ctx
|
||||
// .GuildColors
|
||||
// .FirstOrDefaultAsync(x => x.GuildId == guildId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Utility
|
||||
{
|
||||
[Group("sclr")]
|
||||
public class GuildColorsCommands : NadekoModule<IGuildColorsService>
|
||||
{
|
||||
|
||||
[Cmd]
|
||||
[UserPerm(GuildPerm.ManageGuild)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ServerColorsShow()
|
||||
{
|
||||
EmbedBuilder[] ebs =
|
||||
[
|
||||
CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithDescription("\\✅"),
|
||||
CreateEmbed()
|
||||
.WithPendingColor()
|
||||
.WithDescription("\\⏳\\⚠️"),
|
||||
CreateEmbed()
|
||||
.WithErrorColor()
|
||||
.WithDescription("\\❌")
|
||||
];
|
||||
|
||||
await Response()
|
||||
.Embeds(ebs)
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[UserPerm(GuildPerm.ManageGuild)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ServerColorOk([Leftover] Rgba32? color = null)
|
||||
{
|
||||
await _service.SetOkColor(ctx.Guild.Id, color);
|
||||
|
||||
await Response().Confirm(strs.server_color_set).SendAsync();
|
||||
await ServerColorsShow();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[UserPerm(GuildPerm.ManageGuild)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ServerColorPending([Leftover] Rgba32? color = null)
|
||||
{
|
||||
await _service.SetPendingColor(ctx.Guild.Id, color);
|
||||
|
||||
await Response().Confirm(strs.server_color_set).SendAsync();
|
||||
await ServerColorsShow();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[UserPerm(GuildPerm.ManageGuild)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ServerColorError([Leftover] Rgba32? color = null)
|
||||
{
|
||||
await _service.SetErrorColor(ctx.Guild.Id, color);
|
||||
|
||||
await Response().Confirm(strs.server_color_set).SendAsync();
|
||||
await ServerColorsShow();
|
||||
}
|
||||
}
|
||||
}
|
@@ -48,7 +48,7 @@ public partial class Utility
|
||||
if (string.IsNullOrWhiteSpace(features))
|
||||
features = "-";
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.WithAuthor(GetText(strs.server_info))
|
||||
.WithTitle(guild.Name)
|
||||
.AddField(GetText(strs.id), guild.Id.ToString(), true)
|
||||
@@ -81,7 +81,7 @@ public partial class Utility
|
||||
return;
|
||||
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22);
|
||||
var usercount = (await ch.GetUsersAsync().FlattenAsync()).Count();
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.WithTitle(ch.Name)
|
||||
.WithDescription(ch.Topic?.SanitizeMentions(true))
|
||||
.AddField(GetText(strs.id), ch.Id.ToString(), true)
|
||||
@@ -101,7 +101,7 @@ public partial class Utility
|
||||
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)
|
||||
.AddMilliseconds(role.Id >> 22);
|
||||
var usercount = role.Members.LongCount();
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.WithTitle(role.Name.TrimTo(128))
|
||||
.WithDescription(role.Permissions.ToList().Join(" | "))
|
||||
.AddField(GetText(strs.id), role.Id.ToString(), true)
|
||||
@@ -129,7 +129,7 @@ public partial class Utility
|
||||
if (user is null)
|
||||
return;
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.AddField(GetText(strs.name), $"**{user.Username}**#{user.Discriminator}", true);
|
||||
if (!string.IsNullOrWhiteSpace(user.Nickname))
|
||||
embed.AddField(GetText(strs.nickname), user.Nickname, true);
|
||||
|
@@ -47,9 +47,9 @@ public partial class Utility
|
||||
var i = 1;
|
||||
|
||||
if (!invs.Any())
|
||||
return _sender.CreateEmbed().WithErrorColor().WithDescription(GetText(strs.no_invites));
|
||||
return CreateEmbed().WithErrorColor().WithDescription(GetText(strs.no_invites));
|
||||
|
||||
var embed = _sender.CreateEmbed().WithOkColor();
|
||||
var embed = CreateEmbed().WithOkColor();
|
||||
foreach (var inv in invs)
|
||||
{
|
||||
var expiryString = inv.MaxAge is null or 0 || inv.CreatedAt is null
|
||||
|
@@ -147,7 +147,7 @@ public partial class Utility
|
||||
private async Task ShowQuoteData(Quote quote)
|
||||
{
|
||||
var inter = CreateEditInteraction(quote.Id, quote);
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle($"{GetText(strs.quote_id($"`{new kwum(quote.Id)}"))}`")
|
||||
.WithDescription(Format.Sanitize(quote.Text).Replace("](", "]\\(").TrimTo(4096))
|
||||
@@ -188,7 +188,7 @@ public partial class Utility
|
||||
|
||||
var text = quote.Keyword.ToLowerInvariant() + ": " + quote.Text;
|
||||
|
||||
return _sender.CreateEmbed()
|
||||
return CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle($"{new kwum(quote.Id)} 💬 ")
|
||||
.WithDescription(text);
|
||||
@@ -266,7 +266,7 @@ public partial class Utility
|
||||
if (q is not null)
|
||||
{
|
||||
await Response()
|
||||
.Embed(_sender.CreateEmbed()
|
||||
.Embed(CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.quote_edited))
|
||||
.WithDescription($"#{quoteId}")
|
||||
|
@@ -97,7 +97,7 @@ public partial class Utility
|
||||
if (--page < 0)
|
||||
return;
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(guildId is not null
|
||||
? strs.reminder_server_list
|
||||
|
@@ -211,7 +211,7 @@ public class RemindService : INService, IReadyExecutor, IRemindService
|
||||
else
|
||||
{
|
||||
await res
|
||||
.Embed(_sender.CreateEmbed()
|
||||
.Embed(_sender.CreateEmbed(r.ServerId)
|
||||
.WithOkColor()
|
||||
.WithTitle("Reminder")
|
||||
.AddField("Created At",
|
||||
|
@@ -64,7 +64,7 @@ public partial class Utility
|
||||
}
|
||||
|
||||
var description = GetRepeaterInfoString(removed);
|
||||
await Response().Embed(_sender.CreateEmbed()
|
||||
await Response().Embed(CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.repeater_removed(index + 1)))
|
||||
.WithDescription(description)).SendAsync();
|
||||
@@ -187,7 +187,7 @@ public partial class Utility
|
||||
}
|
||||
|
||||
var description = GetRepeaterInfoString(runner);
|
||||
await Response().Embed(_sender.CreateEmbed()
|
||||
await Response().Embed(CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.repeater_created))
|
||||
.WithDescription(description)).SendAsync();
|
||||
@@ -205,7 +205,7 @@ public partial class Utility
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = _sender.CreateEmbed().WithTitle(GetText(strs.list_of_repeaters)).WithOkColor();
|
||||
var embed = CreateEmbed().WithTitle(GetText(strs.list_of_repeaters)).WithOkColor();
|
||||
|
||||
var i = 0;
|
||||
foreach (var runner in repeaters.OrderBy(r => r.Repeater.Id))
|
||||
|
@@ -51,7 +51,7 @@ public partial class Utility
|
||||
.AddFooter(false)
|
||||
.Page((items, _) =>
|
||||
{
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.todo_list));
|
||||
|
||||
@@ -94,6 +94,18 @@ public partial class Utility
|
||||
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task TodoUncomplete(kwum todoId)
|
||||
{
|
||||
if (!await _service.UncompleteTodoAsync(ctx.User.Id, todoId))
|
||||
{
|
||||
await Response().Error(strs.todo_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task TodoDelete(kwum todoId)
|
||||
@@ -175,7 +187,7 @@ public partial class Utility
|
||||
.CurrentPage(page)
|
||||
.Page((items, _) =>
|
||||
{
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithTitle(GetText(strs.todo_archive_list))
|
||||
.WithOkColor();
|
||||
|
||||
@@ -206,7 +218,7 @@ public partial class Utility
|
||||
.AddFooter(false)
|
||||
.Page((items, _) =>
|
||||
{
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.todo_archived_list));
|
||||
|
||||
|
@@ -21,22 +21,23 @@ public sealed class TodoService : INService
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
if (await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.ArchiveId == null)
|
||||
.CountAsync() >= TODO_MAX_COUNT)
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.ArchiveId == null)
|
||||
.CountAsync()
|
||||
>= TODO_MAX_COUNT)
|
||||
{
|
||||
return TodoAddResult.MaxLimitReached;
|
||||
}
|
||||
|
||||
await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.InsertAsync(() => new TodoModel()
|
||||
{
|
||||
UserId = userId,
|
||||
Todo = todo,
|
||||
DateAdded = DateTime.UtcNow,
|
||||
IsDone = false,
|
||||
});
|
||||
.GetTable<TodoModel>()
|
||||
.InsertAsync(() => new TodoModel()
|
||||
{
|
||||
UserId = userId,
|
||||
Todo = todo,
|
||||
DateAdded = DateTime.UtcNow,
|
||||
IsDone = false,
|
||||
});
|
||||
|
||||
return TodoAddResult.Success;
|
||||
}
|
||||
@@ -45,10 +46,11 @@ public sealed class TodoService : INService
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
return await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.Set(x => x.Todo, newMessage)
|
||||
.UpdateAsync() > 0;
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.Set(x => x.Todo, newMessage)
|
||||
.UpdateAsync()
|
||||
> 0;
|
||||
}
|
||||
|
||||
public async Task<TodoModel[]> GetAllTodosAsync(ulong userId)
|
||||
@@ -56,9 +58,9 @@ public sealed class TodoService : INService
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
return await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.ArchiveId == null)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.ArchiveId == null)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public async Task<bool> CompleteTodoAsync(ulong userId, int todoId)
|
||||
@@ -66,10 +68,23 @@ public sealed class TodoService : INService
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var count = await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.Set(x => x.IsDone, true)
|
||||
.UpdateAsync();
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.Set(x => x.IsDone, true)
|
||||
.UpdateAsync();
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UncompleteTodoAsync(ulong userId, int todoId)
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var count = await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.Set(x => x.IsDone, false)
|
||||
.UpdateAsync();
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
@@ -79,9 +94,9 @@ public sealed class TodoService : INService
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var count = await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.DeleteAsync();
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.DeleteAsync();
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
@@ -91,9 +106,9 @@ public sealed class TodoService : INService
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.ArchiveId == null)
|
||||
.DeleteAsync();
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.ArchiveId == null)
|
||||
.DeleteAsync();
|
||||
}
|
||||
|
||||
public async Task<ArchiveTodoResult> ArchiveTodosAsync(ulong userId, string name)
|
||||
@@ -106,28 +121,28 @@ public sealed class TodoService : INService
|
||||
|
||||
// check if the user reached the limit
|
||||
var count = await ctx
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.Where(x => x.UserId == userId)
|
||||
.CountAsync();
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.Where(x => x.UserId == userId)
|
||||
.CountAsync();
|
||||
|
||||
if (count >= ARCHIVE_MAX_COUNT)
|
||||
return ArchiveTodoResult.MaxLimitReached;
|
||||
|
||||
var inserted = await ctx
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.InsertWithOutputAsync(() => new ArchivedTodoListModel()
|
||||
{
|
||||
UserId = userId,
|
||||
Name = name,
|
||||
});
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.InsertWithOutputAsync(() => new ArchivedTodoListModel()
|
||||
{
|
||||
UserId = userId,
|
||||
Name = name,
|
||||
});
|
||||
|
||||
// mark all existing todos as archived
|
||||
|
||||
var updated = await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.ArchiveId == null)
|
||||
.Set(x => x.ArchiveId, inserted.Id)
|
||||
.UpdateAsync();
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.ArchiveId == null)
|
||||
.Set(x => x.ArchiveId, inserted.Id)
|
||||
.UpdateAsync();
|
||||
|
||||
if (updated == 0)
|
||||
{
|
||||
@@ -140,7 +155,7 @@ public sealed class TodoService : INService
|
||||
|
||||
return ArchiveTodoResult.NoTodos;
|
||||
}
|
||||
|
||||
|
||||
await tr.CommitAsync();
|
||||
|
||||
return ArchiveTodoResult.Success;
|
||||
@@ -152,9 +167,9 @@ public sealed class TodoService : INService
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
return await ctx
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.Where(x => x.UserId == userId)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.Where(x => x.UserId == userId)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public async Task<ArchivedTodoListModel?> GetArchivedTodoListAsync(ulong userId, int archiveId)
|
||||
@@ -162,10 +177,10 @@ public sealed class TodoService : INService
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
return await ctx
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == archiveId)
|
||||
.LoadWith(x => x.Items)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == archiveId)
|
||||
.LoadWith(x => x.Items)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public async Task<bool> ArchiveDeleteAsync(ulong userId, int archiveId)
|
||||
@@ -173,9 +188,9 @@ public sealed class TodoService : INService
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var count = await ctx
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == archiveId)
|
||||
.DeleteAsync();
|
||||
.GetTable<ArchivedTodoListModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == archiveId)
|
||||
.DeleteAsync();
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
@@ -183,10 +198,10 @@ public sealed class TodoService : INService
|
||||
public async Task<TodoModel?> GetTodoAsync(ulong userId, int todoId)
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
|
||||
return await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
}
|
||||
}
|
@@ -13,7 +13,7 @@ public partial class Utility
|
||||
{
|
||||
var units = await _service.GetUnitsAsync();
|
||||
|
||||
var embed = _sender.CreateEmbed().WithTitle(GetText(strs.convertlist)).WithOkColor();
|
||||
var embed = CreateEmbed().WithTitle(GetText(strs.convertlist)).WithOkColor();
|
||||
|
||||
|
||||
foreach (var g in units.GroupBy(x => x.UnitType))
|
||||
|
@@ -131,12 +131,12 @@ public partial class Utility : NadekoModule
|
||||
{
|
||||
if (names.Count == 0)
|
||||
{
|
||||
return _sender.CreateEmbed()
|
||||
return CreateEmbed()
|
||||
.WithErrorColor()
|
||||
.WithDescription(GetText(strs.nobody_playing_game));
|
||||
}
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor();
|
||||
|
||||
var users = names.Join('\n');
|
||||
@@ -180,11 +180,11 @@ public partial class Utility : NadekoModule
|
||||
.Page((pageUsers, _) =>
|
||||
{
|
||||
if (pageUsers.Count == 0)
|
||||
return _sender.CreateEmbed().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page));
|
||||
return CreateEmbed().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page));
|
||||
|
||||
var roleName = Format.Bold(role?.Name ?? "No Role");
|
||||
|
||||
return _sender.CreateEmbed()
|
||||
return CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.inrole_list(roleName, roleUsers.Count)))
|
||||
.WithDescription(string.Join("\n", pageUsers));
|
||||
@@ -327,7 +327,7 @@ public partial class Utility : NadekoModule
|
||||
if (string.IsNullOrWhiteSpace(ownerIds))
|
||||
ownerIds = "-";
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithAuthor($"NadekoBot v{StatsService.BotVersion}",
|
||||
"https://nadeko-pictures.nyc3.digitaloceanspaces.com/other/avatar.png",
|
||||
@@ -583,12 +583,12 @@ public partial class Utility : NadekoModule
|
||||
{
|
||||
if (!guilds.Any())
|
||||
{
|
||||
return _sender.CreateEmbed()
|
||||
return CreateEmbed()
|
||||
.WithDescription(GetText(strs.listservers_none))
|
||||
.WithErrorColor();
|
||||
}
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
var embed = CreateEmbed()
|
||||
.WithOkColor();
|
||||
foreach (var guild in guilds)
|
||||
embed.AddField(guild.Name, GetText(strs.listservers(guild.Id, guild.MemberCount, guild.OwnerId)));
|
||||
@@ -770,7 +770,7 @@ public partial class Utility : NadekoModule
|
||||
var output = result.ReturnValue?.ToString();
|
||||
if (!string.IsNullOrWhiteSpace(output))
|
||||
{
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.AddField("Code", scriptText)
|
||||
.AddField("Output", output.TrimTo(512)!);
|
||||
@@ -796,7 +796,7 @@ public partial class Utility : NadekoModule
|
||||
return;
|
||||
}
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
var eb = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithDescription(msg.Content)
|
||||
.WithAuthor(msg.Author)
|
||||
|
Reference in New Issue
Block a user