mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-05 05:26:28 +03:00
Add /mute command (timeouts only) (#44)
Co-authored-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
7a4e20852e
commit
0e3e562b22
13 changed files with 1477 additions and 745 deletions
|
@ -1,3 +1,4 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Text.Json;
|
||||
using Boyfriend.Data;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
@ -11,9 +12,9 @@ namespace Boyfriend.Services.Data;
|
|||
/// Handles saving, loading, initializing and providing <see cref="GuildData" />.
|
||||
/// </summary>
|
||||
public class GuildDataService : IHostedService {
|
||||
private readonly Dictionary<Snowflake, GuildData> _datas = new();
|
||||
private readonly IDiscordRestGuildAPI _guildApi;
|
||||
private readonly ILogger<GuildDataService> _logger;
|
||||
private readonly ConcurrentDictionary<Snowflake, GuildData> _datas = new();
|
||||
private readonly IDiscordRestGuildAPI _guildApi;
|
||||
private readonly ILogger<GuildDataService> _logger;
|
||||
|
||||
// https://github.com/dotnet/aspnetcore/issues/39139
|
||||
public GuildDataService(
|
||||
|
@ -85,8 +86,6 @@ public class GuildDataService : IHostedService {
|
|||
var memberResult = await _guildApi.GetGuildMemberAsync(guildId, data.Id.ToDiscordSnowflake(), ct);
|
||||
if (memberResult.IsSuccess)
|
||||
data.Roles = memberResult.Entity.Roles.ToList();
|
||||
else
|
||||
_logger.LogWarning("Error in member retrieval.\n{ErrorMessage}", memberResult.Error.Message);
|
||||
|
||||
memberData.Add(data.Id, data);
|
||||
}
|
||||
|
@ -95,7 +94,7 @@ public class GuildDataService : IHostedService {
|
|||
await configuration ?? new GuildConfiguration(), configurationPath,
|
||||
await events ?? new Dictionary<ulong, ScheduledEventData>(), scheduledEventsPath,
|
||||
memberData, memberDataPath);
|
||||
_datas.Add(guildId, finalData);
|
||||
while (!_datas.ContainsKey(guildId)) _datas.TryAdd(guildId, finalData);
|
||||
return finalData;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,14 +87,9 @@ public class GuildUpdateService : BackgroundService {
|
|||
|
||||
foreach (var memberData in data.MemberData.Values) {
|
||||
var userIdSnowflake = memberData.Id.ToDiscordSnowflake();
|
||||
if (!memberData.Roles.Contains(defaultRoleSnowflake)) {
|
||||
var defaultRoleResult = await _guildApi.AddGuildMemberRoleAsync(
|
||||
if (defaultRoleSnowflake.Value is not 0 && !memberData.Roles.Contains(defaultRoleSnowflake))
|
||||
_ = _guildApi.AddGuildMemberRoleAsync(
|
||||
guildId, userIdSnowflake, defaultRoleSnowflake, ct: ct);
|
||||
if (!defaultRoleResult.IsSuccess)
|
||||
_logger.LogWarning(
|
||||
"Error in automatic default role add request.\n{ErrorMessage}",
|
||||
defaultRoleResult.Error.Message);
|
||||
}
|
||||
|
||||
if (DateTimeOffset.UtcNow > memberData.BannedUntil) {
|
||||
var unbanResult = await _guildApi.RemoveGuildBanAsync(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue