Fixed some aliases and reworked namespaces

This commit is contained in:
Kwoth
2024-04-27 16:03:48 +00:00
parent e0819f760c
commit 812b865add
344 changed files with 3166 additions and 3314 deletions

View File

@@ -2,7 +2,7 @@
using Microsoft.EntityFrameworkCore;
using NadekoBot.Db;
using NadekoBot.Modules.Utility.Services;
using Nadeko.Bot.Db.Models;
using NadekoBot.Db.Models;
namespace NadekoBot.Modules.Utility;

View File

@@ -2,7 +2,7 @@
using Microsoft.EntityFrameworkCore;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Db;
using Nadeko.Bot.Db.Models;
using NadekoBot.Db.Models;
namespace NadekoBot.Modules.Utility.Services;

View File

@@ -25,7 +25,7 @@ public partial class Utility
.WithDescription(GetText(strs.config_not_found(Format.Code(name))))
.AddField(GetText(strs.config_list), string.Join("\n", configNames));
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
return;
}
@@ -48,7 +48,7 @@ public partial class Utility
.WithTitle(GetText(strs.config_list))
.WithDescription(string.Join("\n", configNames));
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
return;
}
@@ -63,7 +63,7 @@ public partial class Utility
.WithDescription(GetText(strs.config_not_found(Format.Code(name))))
.AddField(GetText(strs.config_list), string.Join("\n", configNames));
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
return;
}
@@ -78,7 +78,7 @@ public partial class Utility
var embed = _eb.Create().WithOkColor().WithTitle($"⚙️ {setting.Name}").WithDescription(propStrings);
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
return;
}
// if the prop is invalid -> print error and list of
@@ -94,7 +94,7 @@ public partial class Utility
strs.config_prop_not_found(Format.Code(prop), Format.Code(name))))
.AddField($"⚙️ {setting.Name}", propStrings);
await ctx.Channel.EmbedAsync(propErrorEmbed);
await EmbedAsync(propErrorEmbed);
return;
}
@@ -120,7 +120,7 @@ public partial class Utility
if (!string.IsNullOrWhiteSpace(comment))
embed.AddField("Comment", comment);
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
return;
}

View File

@@ -22,7 +22,7 @@ public partial class Utility
.WithTitle(GetText(strs.giveaway_starting))
.WithDescription(message);
var startingMsg = await ctx.Channel.EmbedAsync(eb);
var startingMsg = await EmbedAsync(eb);
var maybeId =
await _service.StartGiveawayAsync(ctx.Guild.Id, ctx.Channel.Id, startingMsg.Id, duration, message);
@@ -112,7 +112,7 @@ public partial class Utility
eb.AddField($"id: {new kwum(g.Id)}", g.Message, true);
}
await ctx.Channel.EmbedAsync(eb);
await EmbedAsync(eb);
}
}
}

View File

@@ -75,7 +75,7 @@ public partial class Utility
string.Join(" ", guild.Emotes.Shuffle().Take(20).Select(e => $"{e.Name} {e}")).TrimTo(1020));
}
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
}
[Cmd]
@@ -94,7 +94,7 @@ public partial class Utility
.AddField(GetText(strs.created_at), $"{createdAt:dd.MM.yyyy HH:mm}", true)
.AddField(GetText(strs.users), usercount.ToString(), true)
.WithOkColor();
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
}
[Cmd]
@@ -121,7 +121,7 @@ public partial class Utility
if (!string.IsNullOrWhiteSpace(role.GetIconUrl()))
embed = embed.WithThumbnailUrl(role.GetIconUrl());
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
}
[Cmd]
@@ -165,7 +165,7 @@ public partial class Utility
if (av.IsAbsoluteUri)
embed.WithThumbnailUrl(av.ToString());
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
}
private DateTimeOffset? GetJoinedAt(IGuildUser user)
@@ -204,7 +204,7 @@ public partial class Utility
kvp.Value)));
}
await ctx.Channel.EmbedAsync(_eb.Create()
await EmbedAsync(_eb.Create()
.WithTitle(GetText(strs.activity_page(page + 1)))
.WithOkColor()
.WithFooter(GetText(

View File

@@ -1,8 +1,7 @@
#nullable disable warnings
using NadekoBot.Common;
using NadekoBot.Common.Yml;
using NadekoBot.Db;
using Nadeko.Bot.Db.Models;
using NadekoBot.Db.Models;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
@@ -105,7 +104,7 @@ public partial class Utility
var text = SmartText.CreateFrom(quote.Text);
text = await repSvc.ReplaceAsync(text, repCtx);
await ctx.Channel.SendAsync($"`#{quote.Id}` 📣 " + text, true);
await ctx.Channel.SendAsync($"`#{quote.Id}` 📣 " + text, true, replyTo: ctx.Message);
}
[Cmd]
@@ -214,7 +213,7 @@ public partial class Utility
var text = SmartText.CreateFrom(quote.Text);
text = await repSvc.ReplaceAsync(text, repCtx);
await ctx.Channel.SendAsync(infoText + text, true);
await ctx.Channel.SendAsync(infoText + text, true, replyTo: ctx.Message);
}
[Cmd]

View File

@@ -1,7 +1,7 @@
#nullable disable warnings
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using Nadeko.Bot.Db.Models;
using NadekoBot.Db.Models;
namespace NadekoBot.Modules.Utility;

View File

@@ -2,7 +2,7 @@
using Humanizer.Localisation;
using NadekoBot.Db;
using NadekoBot.Modules.Utility.Services;
using Nadeko.Bot.Db.Models;
using NadekoBot.Db.Models;
namespace NadekoBot.Modules.Utility;
@@ -127,7 +127,7 @@ public partial class Utility
embed.WithDescription(GetText(strs.reminders_none));
embed.AddPaginatedFooter(page + 1, null);
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
}
[Cmd]

View File

@@ -3,7 +3,7 @@ using System.Globalization;
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using NadekoBot.Common.ModuleBehaviors;
using Nadeko.Bot.Db.Models;
using NadekoBot.Db.Models;
using System.Text.RegularExpressions;
namespace NadekoBot.Modules.Utility.Services;

View File

@@ -1,5 +1,4 @@
using LinqToDB.Common;
using NadekoBot.Common.TypeReaders;
using NadekoBot.Common.TypeReaders;
using NadekoBot.Common.TypeReaders.Models;
using NadekoBot.Modules.Utility.Services;
@@ -65,7 +64,7 @@ public partial class Utility
}
var description = GetRepeaterInfoString(removed);
await ctx.Channel.EmbedAsync(_eb.Create()
await EmbedAsync(_eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.repeater_removed(index + 1)))
.WithDescription(description));
@@ -188,7 +187,7 @@ public partial class Utility
}
var description = GetRepeaterInfoString(runner);
await ctx.Channel.EmbedAsync(_eb.Create()
await EmbedAsync(_eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.repeater_created))
.WithDescription(description));
@@ -216,7 +215,7 @@ public partial class Utility
embed.AddField(name, description);
}
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
}
private string GetRepeaterInfoString(RunningRepeater runner)

View File

@@ -1,9 +1,8 @@
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Common;
using NadekoBot.Common.ModuleBehaviors;
using Nadeko.Bot.Db.Models;
using NadekoBot.Db.Models;
namespace NadekoBot.Modules.Utility.Services;

View File

@@ -1,5 +1,5 @@
#nullable disable
using Nadeko.Bot.Db.Models;
using NadekoBot.Db.Models;
namespace NadekoBot.Modules.Utility.Services;

View File

@@ -2,7 +2,7 @@
using NadekoBot.Db;
using NadekoBot.Modules.Utility.Common;
using NadekoBot.Modules.Utility.Common.Exceptions;
using Nadeko.Bot.Db.Models;
using NadekoBot.Db.Models;
using System.Net;
namespace NadekoBot.Modules.Utility.Services;

View File

@@ -22,7 +22,7 @@ public partial class Utility
string.Join(", ", g.Select(x => x.Triggers.FirstOrDefault()).OrderBy(x => x)));
}
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
}
[Cmd]

View File

@@ -68,14 +68,24 @@ public partial class Utility : NadekoModule
[Priority(1)]
public async Task Say(ITextChannel channel, [Leftover] SmartText message)
{
// var rep = new ReplacementBuilder()
// .WithDefault(ctx.User, channel, (SocketGuild)ctx.Guild, (DiscordSocketClient)ctx.Client)
// .Build();
if (!((IGuildUser)ctx.User).GetPermissions(channel).SendMessages)
{
await ReplyErrorLocalizedAsync(strs.insuf_perms_u);
return;
}
if (!((ctx.Guild as SocketGuild)?.CurrentUser.GetPermissions(channel).SendMessages ?? false))
{
await ReplyErrorLocalizedAsync(strs.insuf_perms_i);
return;
}
var repCtx = new ReplacementContext(Context);
message = await repSvc.ReplaceAsync(message, repCtx);
await channel.SendAsync(message, !((IGuildUser)ctx.User).GuildPermissions.MentionEveryone);
await channel.SendAsync(message,
!((IGuildUser)ctx.User).GuildPermissions.MentionEveryone,
replyTo: ctx.Message);
}
[Cmd]
@@ -101,12 +111,14 @@ public partial class Utility : NadekoModule
var rng = new NadekoRandom();
var arr = await Task.Run(() => socketGuild.Users
.Where(u => u.Activities.FirstOrDefault()?.Name?.Trim().ToUpperInvariant()
== game)
.Select(u => u.Username)
.OrderBy(_ => rng.Next())
.Take(60)
.ToArray());
.Where(u => u.Activities.FirstOrDefault()
?.Name?.Trim()
.ToUpperInvariant()
== game)
.Select(u => u.Username)
.OrderBy(_ => rng.Next())
.Take(60)
.ToArray());
var i = 0;
if (arr.Length == 0)
@@ -116,7 +128,7 @@ public partial class Utility : NadekoModule
await SendConfirmAsync("```css\n"
+ string.Join("\n",
arr.GroupBy(_ => i++ / 2)
.Select(ig => string.Concat(ig.Select(el => $"• {el,-27}"))))
.Select(ig => string.Concat(ig.Select(el => $"• {el,-27}"))))
+ "\n```");
}
}
@@ -137,8 +149,8 @@ public partial class Utility : NadekoModule
);
var roleUsers = users.Where(u => role is null ? u.RoleIds.Count == 1 : u.RoleIds.Contains(role.Id))
.Select(u => $"`{u.Id,18}` {u}")
.ToArray();
.Select(u => $"`{u.Id,18}` {u}")
.ToArray();
await ctx.SendPaginatedConfirmAsync(page,
cur =>
@@ -149,9 +161,9 @@ public partial class Utility : NadekoModule
return _eb.Create().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page));
return _eb.Create()
.WithOkColor()
.WithTitle(GetText(strs.inrole_list(Format.Bold(role?.Name ?? "No Role"), roleUsers.Length)))
.WithDescription(string.Join("\n", pageUsers));
.WithOkColor()
.WithTitle(GetText(strs.inrole_list(Format.Bold(role?.Name ?? "No Role"), roleUsers.Length)))
.WithDescription(string.Join("\n", pageUsers));
},
roleUsers.Length,
20);
@@ -171,14 +183,14 @@ public partial class Utility : NadekoModule
var user = who == MeOrBot.Me ? (IGuildUser)ctx.User : ((SocketGuild)ctx.Guild).CurrentUser;
var perms = user.GetPermissions((ITextChannel)ctx.Channel);
foreach (var p in perms.GetType()
.GetProperties()
.Where(static p =>
{
var method = p.GetGetMethod();
if (method is null)
return false;
return !method.GetParameters().Any();
}))
.GetProperties()
.Where(static p =>
{
var method = p.GetGetMethod();
if (method is null)
return false;
return !method.GetParameters().Any();
}))
builder.AppendLine($"{p.Name} : {p.GetValue(perms, null)}");
await SendConfirmAsync(builder.ToString());
}
@@ -223,11 +235,11 @@ public partial class Utility : NadekoModule
if (target is not null)
{
var roles = target.GetRoles()
.Except(new[] { guild.EveryoneRole })
.OrderBy(r => -r.Position)
.Skip((page - 1) * rolesPerPage)
.Take(rolesPerPage)
.ToArray();
.Except(new[] { guild.EveryoneRole })
.OrderBy(r => -r.Position)
.Skip((page - 1) * rolesPerPage)
.Take(rolesPerPage)
.ToArray();
if (!roles.Any())
await ReplyErrorLocalizedAsync(strs.no_roles_on_page);
else
@@ -239,10 +251,10 @@ public partial class Utility : NadekoModule
else
{
var roles = guild.Roles.Except(new[] { guild.EveryoneRole })
.OrderBy(r => -r.Position)
.Skip((page - 1) * rolesPerPage)
.Take(rolesPerPage)
.ToArray();
.OrderBy(r => -r.Position)
.Skip((page - 1) * rolesPerPage)
.Take(rolesPerPage)
.ToArray();
if (!roles.Any())
await ReplyErrorLocalizedAsync(strs.no_roles_on_page);
else
@@ -279,30 +291,30 @@ public partial class Utility : NadekoModule
if (string.IsNullOrWhiteSpace(ownerIds))
ownerIds = "-";
await ctx.Channel.EmbedAsync(_eb.Create()
.WithOkColor()
.WithAuthor($"NadekoBot v{StatsService.BOT_VERSION}",
"https://nadeko-pictures.nyc3.digitaloceanspaces.com/other/avatar.png",
"https://nadekobot.readthedocs.io/en/latest/")
.AddField(GetText(strs.author), _stats.Author, true)
.AddField(GetText(strs.botid), _client.CurrentUser.Id.ToString(), true)
.AddField(GetText(strs.shard),
$"#{_client.ShardId} / {_creds.TotalShards}",
true)
.AddField(GetText(strs.commands_ran), _stats.CommandsRan.ToString(), true)
.AddField(GetText(strs.messages),
$"{_stats.MessageCounter} ({_stats.MessagesPerSecond:F2}/sec)",
true)
.AddField(GetText(strs.memory),
FormattableString.Invariant($"{_stats.GetPrivateMemoryMegabytes():F2} MB"),
true)
.AddField(GetText(strs.owner_ids), ownerIds, true)
.AddField(GetText(strs.uptime), _stats.GetUptimeString("\n"), true)
.AddField(GetText(strs.presence),
GetText(strs.presence_txt(_coord.GetGuildCount(),
_stats.TextChannels,
_stats.VoiceChannels)),
true));
await EmbedAsync(_eb.Create()
.WithOkColor()
.WithAuthor($"NadekoBot v{StatsService.BOT_VERSION}",
"https://nadeko-pictures.nyc3.digitaloceanspaces.com/other/avatar.png",
"https://nadekobot.readthedocs.io/en/latest/")
.AddField(GetText(strs.author), _stats.Author, true)
.AddField(GetText(strs.botid), _client.CurrentUser.Id.ToString(), true)
.AddField(GetText(strs.shard),
$"#{_client.ShardId} / {_creds.TotalShards}",
true)
.AddField(GetText(strs.commands_ran), _stats.CommandsRan.ToString(), true)
.AddField(GetText(strs.messages),
$"{_stats.MessageCounter} ({_stats.MessagesPerSecond:F2}/sec)",
true)
.AddField(GetText(strs.memory),
FormattableString.Invariant($"{_stats.GetPrivateMemoryMegabytes():F2} MB"),
true)
.AddField(GetText(strs.owner_ids), ownerIds, true)
.AddField(GetText(strs.uptime), _stats.GetUptimeString("\n"), true)
.AddField(GetText(strs.presence),
GetText(strs.presence_txt(_coord.GetGuildCount(),
_stats.TextChannels,
_stats.VoiceChannels)),
true));
}
[Cmd]
@@ -485,9 +497,9 @@ public partial class Utility : NadekoModule
return;
var guilds = _client.Guilds.OrderBy(g => g.Name)
.Skip(page * 15)
.Take(15)
.ToList();
.Skip(page * 15)
.Take(15)
.ToList();
if (!guilds.Any())
{
@@ -499,7 +511,7 @@ public partial class Utility : NadekoModule
foreach (var guild in guilds)
embed.AddField(guild.Name, GetText(strs.listservers(guild.Id, guild.MemberCount, guild.OwnerId)));
await ctx.Channel.EmbedAsync(embed);
await EmbedAsync(embed);
}
[Cmd]
@@ -536,7 +548,7 @@ public partial class Utility : NadekoModule
{
Content = msg.Content,
Embeds = msg.Embeds
.Map(x => new SmartEmbedArrayElementText(x))
.Map(x => new SmartEmbedArrayElementText(x))
}.ToJson(_showEmbedSerializerOptions);
await SendConfirmAsync(Format.Code(json, "json").Replace("](", "]\\("));
@@ -552,34 +564,34 @@ public partial class Utility : NadekoModule
var title = $"Chatlog-{ctx.Guild.Name}/#{ctx.Channel.Name}-{DateTime.Now}.txt";
var grouping = msgs.GroupBy(x => $"{x.CreatedAt.Date:dd.MM.yyyy}")
.Select(g => new
{
date = g.Key,
messages = g.OrderBy(x => x.CreatedAt)
.Select(s =>
{
var msg = $"【{s.Timestamp:HH:mm:ss}】{s.Author}:";
if (string.IsNullOrWhiteSpace(s.ToString()))
{
if (s.Attachments.Any())
{
msg += "FILES_UPLOADED: "
+ string.Join("\n", s.Attachments.Select(x => x.Url));
}
else if (s.Embeds.Any())
{
msg += "EMBEDS: "
+ string.Join("\n--------\n",
s.Embeds.Select(x
=> $"Description: {x.Description}"));
}
}
else
msg += s.ToString();
.Select(g => new
{
date = g.Key,
messages = g.OrderBy(x => x.CreatedAt)
.Select(s =>
{
var msg = $"【{s.Timestamp:HH:mm:ss}】{s.Author}:";
if (string.IsNullOrWhiteSpace(s.ToString()))
{
if (s.Attachments.Any())
{
msg += "FILES_UPLOADED: "
+ string.Join("\n", s.Attachments.Select(x => x.Url));
}
else if (s.Embeds.Any())
{
msg += "EMBEDS: "
+ string.Join("\n--------\n",
s.Embeds.Select(x
=> $"Description: {x.Description}"));
}
}
else
msg += s.ToString();
return msg;
})
});
return msg;
})
});
await using var stream = await JsonConvert.SerializeObject(grouping, Formatting.Indented).ToStream();
await ctx.User.SendFileAsync(stream, title, title);
}
@@ -633,15 +645,15 @@ public partial class Utility : NadekoModule
var script = CSharpScript.Create(scriptText,
ScriptOptions.Default
.WithReferences(this.GetType().Assembly)
.WithImports(
"System",
"NadekoBot",
"NadekoBot.Extensions",
"Microsoft.Extensions.DependencyInjection",
"NadekoBot.Common",
"System.Text",
"System.Text.Json"),
.WithReferences(this.GetType().Assembly)
.WithImports(
"System",
"NadekoBot",
"NadekoBot.Extensions",
"Microsoft.Extensions.DependencyInjection",
"NadekoBot.Common",
"System.Text",
"System.Text.Json"),
globalsType: typeof(EvalGlobals));
try
@@ -660,11 +672,11 @@ public partial class Utility : NadekoModule
if (!string.IsNullOrWhiteSpace(output))
{
var eb = _eb.Create(ctx)
.WithOkColor()
.AddField("Code", scriptText)
.AddField("Output", output.TrimTo(512)!);
.WithOkColor()
.AddField("Code", scriptText)
.AddField("Output", output.TrimTo(512)!);
_ = ctx.Channel.EmbedAsync(eb);
_ = EmbedAsync(eb);
}
}
catch (Exception ex)