mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 18:28:27 -04:00
Applied codestyle to all .cs files
This commit is contained in:
@@ -1,12 +1,25 @@
|
||||
#nullable disable
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Modules.Xp.Services;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
using NadekoBot.Modules.Xp.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Xp;
|
||||
|
||||
public partial class Xp : NadekoModule<XpService>
|
||||
{
|
||||
public enum Channel { Channel }
|
||||
|
||||
public enum NotifyPlace
|
||||
{
|
||||
Server = 0,
|
||||
Guild = 0,
|
||||
Global = 1
|
||||
}
|
||||
|
||||
public enum Role { Role }
|
||||
|
||||
public enum Server { Server }
|
||||
|
||||
private readonly DownloadTracker _tracker;
|
||||
private readonly GamblingConfigService _gss;
|
||||
|
||||
@@ -16,7 +29,8 @@ public partial class Xp : NadekoModule<XpService>
|
||||
_gss = gss;
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Experience([Leftover] IUser user = null)
|
||||
{
|
||||
@@ -29,14 +43,15 @@ public partial class Xp : NadekoModule<XpService>
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
public async Task XpRewsReset()
|
||||
{
|
||||
var reply = await PromptUserConfirmAsync(_eb.Create()
|
||||
.WithPendingColor()
|
||||
.WithDescription(GetText(strs.xprewsreset_confirm)));
|
||||
.WithPendingColor()
|
||||
.WithDescription(GetText(strs.xprewsreset_confirm)));
|
||||
|
||||
if (!reply)
|
||||
return;
|
||||
@@ -44,8 +59,9 @@ public partial class Xp : NadekoModule<XpService>
|
||||
await _service.ResetXpRewards(ctx.Guild.Id);
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task XpLevelUpRewards(int page = 1)
|
||||
{
|
||||
@@ -55,58 +71,56 @@ public partial class Xp : NadekoModule<XpService>
|
||||
return Task.CompletedTask;
|
||||
|
||||
var allRewards = _service.GetRoleRewards(ctx.Guild.Id)
|
||||
.OrderBy(x => x.Level)
|
||||
.Select(x =>
|
||||
.OrderBy(x => x.Level)
|
||||
.Select(x =>
|
||||
{
|
||||
var sign = !x.Remove ? @"✅ " : @"❌ ";
|
||||
|
||||
var str = ctx.Guild.GetRole(x.RoleId)?.ToString();
|
||||
|
||||
if (str is null)
|
||||
{
|
||||
str = GetText(strs.role_not_found(Format.Code(x.RoleId.ToString())));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!x.Remove)
|
||||
str = GetText(strs.xp_receive_role(Format.Bold(str)));
|
||||
else
|
||||
str = GetText(strs.xp_lose_role(Format.Bold(str)));
|
||||
}
|
||||
|
||||
return (x.Level, Text: sign + str);
|
||||
})
|
||||
.Concat(_service.GetCurrencyRewards(ctx.Guild.Id)
|
||||
.OrderBy(x => x.Level)
|
||||
.Select(x => (x.Level,
|
||||
Format.Bold(x.Amount + _gss.Data.Currency.Sign))))
|
||||
.GroupBy(x => x.Level)
|
||||
.OrderBy(x => x.Key)
|
||||
.ToList();
|
||||
|
||||
return Context.SendPaginatedConfirmAsync(page,
|
||||
cur =>
|
||||
{
|
||||
var sign = !x.Remove
|
||||
? @"✅ "
|
||||
: @"❌ ";
|
||||
|
||||
var str = ctx.Guild.GetRole(x.RoleId)?.ToString();
|
||||
|
||||
if (str is null)
|
||||
str = GetText(strs.role_not_found(Format.Code(x.RoleId.ToString())));
|
||||
else
|
||||
{
|
||||
if (!x.Remove)
|
||||
str = GetText(strs.xp_receive_role(Format.Bold(str)));
|
||||
else
|
||||
str = GetText(strs.xp_lose_role(Format.Bold(str)));
|
||||
}
|
||||
return (x.Level, Text: sign + str);
|
||||
})
|
||||
.Concat(_service.GetCurrencyRewards(ctx.Guild.Id)
|
||||
.OrderBy(x => x.Level)
|
||||
.Select(x => (x.Level, Format.Bold(x.Amount + _gss.Data.Currency.Sign))))
|
||||
.GroupBy(x => x.Level)
|
||||
.OrderBy(x => x.Key)
|
||||
.ToList();
|
||||
var embed = _eb.Create().WithTitle(GetText(strs.level_up_rewards)).WithOkColor();
|
||||
|
||||
return Context.SendPaginatedConfirmAsync(page, cur =>
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
.WithTitle(GetText(strs.level_up_rewards))
|
||||
.WithOkColor();
|
||||
|
||||
var localRewards = allRewards
|
||||
.Skip(cur * 9)
|
||||
.Take(9)
|
||||
.ToList();
|
||||
var localRewards = allRewards.Skip(cur * 9).Take(9).ToList();
|
||||
|
||||
if (!localRewards.Any())
|
||||
return embed.WithDescription(GetText(strs.no_level_up_rewards));
|
||||
if (!localRewards.Any())
|
||||
return embed.WithDescription(GetText(strs.no_level_up_rewards));
|
||||
|
||||
foreach (var reward in localRewards)
|
||||
{
|
||||
embed.AddField(GetText(strs.level_x(reward.Key)),
|
||||
string.Join("\n", reward.Select(y => y.Item2)));
|
||||
}
|
||||
|
||||
return embed;
|
||||
}, allRewards.Count, 9);
|
||||
foreach (var reward in localRewards)
|
||||
embed.AddField(GetText(strs.level_x(reward.Key)), string.Join("\n", reward.Select(y => y.Item2)));
|
||||
|
||||
return embed;
|
||||
},
|
||||
allRewards.Count,
|
||||
9);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
[BotPerm(GuildPerm.ManageRoles)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@@ -116,8 +130,9 @@ public partial class Xp : NadekoModule<XpService>
|
||||
_service.ResetRoleReward(ctx.Guild.Id, level);
|
||||
await ReplyConfirmLocalizedAsync(strs.xp_role_reward_cleared(level));
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
[BotPerm(GuildPerm.ManageRoles)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@@ -129,16 +144,14 @@ public partial class Xp : NadekoModule<XpService>
|
||||
|
||||
_service.SetRoleReward(ctx.Guild.Id, level, role.Id, action == AddRemove.Remove);
|
||||
if (action == AddRemove.Add)
|
||||
await ReplyConfirmLocalizedAsync(strs.xp_role_reward_add_role(
|
||||
level,
|
||||
Format.Bold(role.ToString())));
|
||||
await ReplyConfirmLocalizedAsync(strs.xp_role_reward_add_role(level, Format.Bold(role.ToString())));
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.xp_role_reward_remove_role(
|
||||
Format.Bold(level.ToString()),
|
||||
await ReplyConfirmLocalizedAsync(strs.xp_role_reward_remove_role(Format.Bold(level.ToString()),
|
||||
Format.Bold(role.ToString())));
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task XpCurrencyReward(int level, int amount = 0)
|
||||
@@ -152,33 +165,20 @@ public partial class Xp : NadekoModule<XpService>
|
||||
if (amount == 0)
|
||||
await ReplyConfirmLocalizedAsync(strs.cur_reward_cleared(level, config.Currency.Sign));
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.cur_reward_added(
|
||||
level, Format.Bold(amount + config.Currency.Sign)));
|
||||
}
|
||||
|
||||
public enum NotifyPlace
|
||||
{
|
||||
Server = 0,
|
||||
Guild = 0,
|
||||
Global = 1,
|
||||
await ReplyConfirmLocalizedAsync(strs.cur_reward_added(level, Format.Bold(amount + config.Currency.Sign)));
|
||||
}
|
||||
|
||||
private string GetNotifLocationString(XpNotificationLocation loc)
|
||||
{
|
||||
if (loc == XpNotificationLocation.Channel)
|
||||
{
|
||||
return GetText(strs.xpn_notif_channel);
|
||||
}
|
||||
if (loc == XpNotificationLocation.Channel) return GetText(strs.xpn_notif_channel);
|
||||
|
||||
if (loc == XpNotificationLocation.Dm)
|
||||
{
|
||||
return GetText(strs.xpn_notif_dm);
|
||||
}
|
||||
if (loc == XpNotificationLocation.Dm) return GetText(strs.xpn_notif_dm);
|
||||
|
||||
return GetText(strs.xpn_notif_disabled);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task XpNotify()
|
||||
{
|
||||
@@ -186,14 +186,15 @@ public partial class Xp : NadekoModule<XpService>
|
||||
var serverSetting = _service.GetNotificationType(ctx.User.Id, ctx.Guild.Id);
|
||||
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
.AddField(GetText(strs.xpn_setting_global), GetNotifLocationString(globalSetting))
|
||||
.AddField(GetText(strs.xpn_setting_server), GetNotifLocationString(serverSetting));
|
||||
.WithOkColor()
|
||||
.AddField(GetText(strs.xpn_setting_global), GetNotifLocationString(globalSetting))
|
||||
.AddField(GetText(strs.xpn_setting_server), GetNotifLocationString(serverSetting));
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task XpNotify(NotifyPlace place, XpNotificationLocation type)
|
||||
{
|
||||
@@ -201,13 +202,12 @@ public partial class Xp : NadekoModule<XpService>
|
||||
await _service.ChangeNotificationType(ctx.User.Id, ctx.Guild.Id, type);
|
||||
else
|
||||
await _service.ChangeNotificationType(ctx.User, type);
|
||||
|
||||
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
public enum Server { Server };
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
public async Task XpExclude(Server _)
|
||||
@@ -215,18 +215,13 @@ public partial class Xp : NadekoModule<XpService>
|
||||
var ex = _service.ToggleExcludeServer(ctx.Guild.Id);
|
||||
|
||||
if (ex)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.excluded(Format.Bold(ctx.Guild.ToString())));
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.not_excluded(Format.Bold(ctx.Guild.ToString())));
|
||||
}
|
||||
}
|
||||
|
||||
public enum Role { Role };
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[UserPerm(GuildPerm.ManageRoles)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task XpExclude(Role _, [Leftover] IRole role)
|
||||
@@ -234,18 +229,13 @@ public partial class Xp : NadekoModule<XpService>
|
||||
var ex = _service.ToggleExcludeRole(ctx.Guild.Id, role.Id);
|
||||
|
||||
if (ex)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.excluded(Format.Bold(role.ToString())));
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.not_excluded(Format.Bold(role.ToString())));
|
||||
}
|
||||
}
|
||||
|
||||
public enum Channel { Channel };
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[UserPerm(GuildPerm.ManageChannels)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task XpExclude(Channel _, [Leftover] IChannel channel = null)
|
||||
@@ -256,31 +246,28 @@ public partial class Xp : NadekoModule<XpService>
|
||||
var ex = _service.ToggleExcludeChannel(ctx.Guild.Id, channel.Id);
|
||||
|
||||
if (ex)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.excluded(Format.Bold(channel.ToString())));
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.not_excluded(Format.Bold(channel.ToString())));
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task XpExclusionList()
|
||||
{
|
||||
var serverExcluded = _service.IsServerExcluded(ctx.Guild.Id);
|
||||
var roles = _service.GetExcludedRoles(ctx.Guild.Id)
|
||||
.Select(x => ctx.Guild.GetRole(x))
|
||||
.Where(x => x != null)
|
||||
.Select(x => $"`role` {x.Mention}")
|
||||
.ToList();
|
||||
.Select(x => ctx.Guild.GetRole(x))
|
||||
.Where(x => x != null)
|
||||
.Select(x => $"`role` {x.Mention}")
|
||||
.ToList();
|
||||
|
||||
var chans = (await _service.GetExcludedChannels(ctx.Guild.Id)
|
||||
.Select(x => ctx.Guild.GetChannelAsync(x))
|
||||
.WhenAll()).Where(x => x != null)
|
||||
.Select(x => $"`channel` <#{x.Id}>")
|
||||
.ToList();
|
||||
.Select(x => ctx.Guild.GetChannelAsync(x))
|
||||
.WhenAll()).Where(x => x != null)
|
||||
.Select(x => $"`channel` <#{x.Id}>")
|
||||
.ToList();
|
||||
|
||||
var rolesStr = roles.Any() ? string.Join("\n", roles) + "\n" : string.Empty;
|
||||
var chansStr = chans.Count > 0 ? string.Join("\n", chans) + "\n" : string.Empty;
|
||||
@@ -291,25 +278,30 @@ public partial class Xp : NadekoModule<XpService>
|
||||
desc += "\n\n" + rolesStr + chansStr;
|
||||
|
||||
var lines = desc.Split('\n');
|
||||
await ctx.SendPaginatedConfirmAsync(0, curpage =>
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
.WithTitle(GetText(strs.exclusion_list))
|
||||
.WithDescription(string.Join('\n', lines.Skip(15 * curpage).Take(15)))
|
||||
.WithOkColor();
|
||||
await ctx.SendPaginatedConfirmAsync(0,
|
||||
curpage =>
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
.WithTitle(GetText(strs.exclusion_list))
|
||||
.WithDescription(string.Join('\n', lines.Skip(15 * curpage).Take(15)))
|
||||
.WithOkColor();
|
||||
|
||||
return embed;
|
||||
}, lines.Length, 15);
|
||||
return embed;
|
||||
},
|
||||
lines.Length,
|
||||
15);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[NadekoOptions(typeof(LbOpts))]
|
||||
[Priority(0)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task XpLeaderboard(params string[] args)
|
||||
=> XpLeaderboard(1, args);
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[NadekoOptions(typeof(LbOpts))]
|
||||
[Priority(1)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@@ -328,32 +320,25 @@ public partial class Xp : NadekoModule<XpService>
|
||||
{
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
||||
|
||||
|
||||
allUsers = _service.GetTopUserXps(ctx.Guild.Id, 1000)
|
||||
.Where(user => socketGuild.GetUser(user.UserId) is not null)
|
||||
.ToList();
|
||||
.Where(user => socketGuild.GetUser(user.UserId) is not null)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(page, curPage =>
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
.WithTitle(GetText(strs.server_leaderboard))
|
||||
.WithOkColor();
|
||||
await ctx.SendPaginatedConfirmAsync(page,
|
||||
curPage =>
|
||||
{
|
||||
var embed = _eb.Create().WithTitle(GetText(strs.server_leaderboard)).WithOkColor();
|
||||
|
||||
List<UserXpStats> users;
|
||||
if (opts.Clean)
|
||||
{
|
||||
users = allUsers.Skip(curPage * 9).Take(9).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
users = _service.GetUserXps(ctx.Guild.Id, curPage);
|
||||
}
|
||||
List<UserXpStats> users;
|
||||
if (opts.Clean)
|
||||
users = allUsers.Skip(curPage * 9).Take(9).ToList();
|
||||
else
|
||||
users = _service.GetUserXps(ctx.Guild.Id, curPage);
|
||||
|
||||
if (!users.Any()) return embed.WithDescription("-");
|
||||
|
||||
if (!users.Any())
|
||||
return embed.WithDescription("-");
|
||||
else
|
||||
{
|
||||
for (var i = 0; i < users.Count; i++)
|
||||
{
|
||||
var levelStats = new LevelStats(users[i].Xp + users[i].AwardedXp);
|
||||
@@ -367,16 +352,19 @@ public partial class Xp : NadekoModule<XpService>
|
||||
else if (userXpData.AwardedXp < 0)
|
||||
awardStr = $"({userXpData.AwardedXp})";
|
||||
|
||||
embed.AddField(
|
||||
$"#{i + 1 + (curPage * 9)} {user?.ToString() ?? users[i].UserId.ToString()}",
|
||||
embed.AddField($"#{i + 1 + (curPage * 9)} {user?.ToString() ?? users[i].UserId.ToString()}",
|
||||
$"{GetText(strs.level_x(levelStats.Level))} - {levelStats.TotalXp}xp {awardStr}");
|
||||
}
|
||||
|
||||
return embed;
|
||||
}
|
||||
}, 900, 9, addPaginatedFooter: false);
|
||||
},
|
||||
900,
|
||||
9,
|
||||
false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task XpGlobalLeaderboard(int page = 1)
|
||||
{
|
||||
@@ -384,27 +372,23 @@ public partial class Xp : NadekoModule<XpService>
|
||||
return;
|
||||
var users = _service.GetUserXps(page);
|
||||
|
||||
var embed = _eb.Create()
|
||||
.WithTitle(GetText(strs.global_leaderboard))
|
||||
.WithOkColor();
|
||||
var embed = _eb.Create().WithTitle(GetText(strs.global_leaderboard)).WithOkColor();
|
||||
|
||||
if (!users.Any())
|
||||
embed.WithDescription("-");
|
||||
else
|
||||
{
|
||||
for (var i = 0; i < users.Length; i++)
|
||||
{
|
||||
var user = users[i];
|
||||
embed.AddField(
|
||||
$"#{i + 1 + (page * 9)} {user.ToString()}",
|
||||
embed.AddField($"#{i + 1 + (page * 9)} {user.ToString()}",
|
||||
$"{GetText(strs.level_x(new LevelStats(users[i].TotalXp).Level))} - {users[i].TotalXp}xp");
|
||||
}
|
||||
}
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
public async Task XpAdd(int amount, ulong userId)
|
||||
@@ -413,18 +397,19 @@ public partial class Xp : NadekoModule<XpService>
|
||||
return;
|
||||
|
||||
_service.AddXp(userId, ctx.Guild.Id, amount);
|
||||
var usr = ((SocketGuild)ctx.Guild).GetUser(userId)?.ToString()
|
||||
?? userId.ToString();
|
||||
var usr = ((SocketGuild)ctx.Guild).GetUser(userId)?.ToString() ?? userId.ToString();
|
||||
await ReplyConfirmLocalizedAsync(strs.modified(Format.Bold(usr), Format.Bold(amount.ToString())));
|
||||
}
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
public Task XpAdd(int amount, [Leftover] IGuildUser user)
|
||||
=> XpAdd(amount, user.Id);
|
||||
|
||||
[NadekoCommand, Aliases]
|
||||
[NadekoCommand]
|
||||
[Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task XpTemplateReload()
|
||||
@@ -433,4 +418,4 @@ public partial class Xp : NadekoModule<XpService>
|
||||
await Task.Delay(1000);
|
||||
await ReplyConfirmLocalizedAsync(strs.template_reloaded);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user