Skip to content

Commit 91313df

Browse files
committed
use a more standard way of creating new warns
1 parent 3fdce09 commit 91313df

5 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/Bot/Systems/Commands/Interaction/Attributes/RequireGuildAdminPreconditionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ IServiceProvider services
1515
return PreconditionResult.FromError("This command can only be executed in a guild.");
1616

1717
var db = services.Get<DatabaseService>();
18-
var data = await db.GetDataAsync(context.Guild.Id);
18+
var data = db.GetData(context.Guild.Id);
1919

2020
var u = await context.Guild.GetUserAsync(context.User.Id);
2121

src/Bot/Systems/Commands/Interaction/Attributes/RequireGuildModeratorPreconditionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ IServiceProvider services
1515
return PreconditionResult.FromError("This command can only be executed in a guild.");
1616

1717
var db = services.Get<DatabaseService>();
18-
var data = await db.GetDataAsync(context.Guild.Id);
18+
var data = db.GetData(context.Guild.Id);
1919

2020
var u =
2121
context.Guild.Cast<SocketGuild>()?.GetUser(context.User.Id)

src/Bot/Systems/Database/DatabaseService.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ public GuildDataV2 GetData(ulong id)
8888

8989
public GuildDataV2 GetData(IGuild guild) => GetData(guild.Id);
9090
public HashSet<GuildDataV2> GetAllData() => _guildDataV2.ValueLock(() => _guildDataV2.FindAll().ToHashSet());
91-
92-
public ValueTask<GuildDataV2> GetDataAsync(ulong id) => new(GetData(id));
9391

9492
public void CreateGuildDataIfNotExists(IGuild guild) =>
9593
_guildDataV2.LockedRef(coll =>
@@ -139,16 +137,16 @@ public bool TryDeleteReminder(Reminder.Reminder reminder) =>
139137

140138
public async Task WarnAsync(IUser issuer, IGuildUser member, string reason)
141139
{
142-
var data = await GetDataAsync(member.GuildId);
143-
144-
data.Moderation.AddWarn(warn =>
140+
var data = GetData(member.GuildId);
141+
142+
data.Moderation.Warns.Add(new WarnV2
145143
{
146-
warn.Issuer = issuer.Id;
147-
warn.Target = member.Id;
148-
warn.Reason = reason;
149-
warn.Date = DateTimeOffset.Now;
144+
Issuer = issuer.Id,
145+
Target = member.Id,
146+
Reason = reason,
147+
Date = DateTimeOffset.Now
150148
});
151-
149+
152150
Save(data);
153151

154152
var e = new EmbedBuilder().WithSuccessColor().WithAuthor(issuer)

src/Bot/Systems/Starboard/StarboardService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public async Task HandleReactionsClearAsync(Cacheable<IUserMessage, ulong> cache
174174
var guildId = channel.Guild.Id;
175175
var messageId = cachedMessage.Id;
176176

177-
var starboard = (await _db.GetDataAsync(guildId)).Settings.Starboard;
177+
var starboard = _db.GetData(guildId).Settings.Starboard;
178178

179179
if (!starboard.Enabled) return;
180180

@@ -292,7 +292,7 @@ public EmbedBuilder GetStarboardEmbed(IMessage message)
292292

293293
private async Task<IMessage> PostToStarboardAsync(IMessage message, int starCount)
294294
{
295-
var data = await _db.GetDataAsync(message.Channel.Cast<IGuildChannel>().GuildId);
295+
var data = _db.GetData(message.Channel.Cast<IGuildChannel>().GuildId);
296296

297297
var starboardChannel = _client.GetChannel(data.Settings.Starboard.Channel);
298298
if (starboardChannel is not ITextChannel starboardTextChannel)

src/Bot/Systems/UserFilter/UserFilterService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public Task OnUserJoined(UserJoinedEventArgs args)
1515
{
1616
ExecuteBackgroundAsync(async () =>
1717
{
18-
var data = await _db.GetDataAsync(args.Guild.Id);
18+
var data = _db.GetData(args.Guild.Id);
1919
var idsToClear = await data.StarscriptTables.UserFilter
2020
.HandleAsync(args.Guild, args.User)
2121
.ToArrayAsync();

0 commit comments

Comments
 (0)