mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Stagger greet dms
This commit is contained in:
@@ -335,7 +335,8 @@ resharper_csharp_wrap_before_binary_opsign = true
|
|||||||
resharper_csharp_wrap_before_invocation_rpar = false
|
resharper_csharp_wrap_before_invocation_rpar = false
|
||||||
resharper_csharp_wrap_parameters_style = chop_if_long
|
resharper_csharp_wrap_parameters_style = chop_if_long
|
||||||
resharper_force_chop_compound_if_expression = false
|
resharper_force_chop_compound_if_expression = false
|
||||||
resharper_keep_existing_linebreaks = false
|
resharper_keep_existing_linebreaks = true
|
||||||
|
resharper_keep_user_linebreaks = true
|
||||||
resharper_max_formal_parameters_on_line = 3
|
resharper_max_formal_parameters_on_line = 3
|
||||||
resharper_place_simple_embedded_statement_on_same_line = false
|
resharper_place_simple_embedded_statement_on_same_line = false
|
||||||
resharper_wrap_chained_binary_expressions = chop_if_long
|
resharper_wrap_chained_binary_expressions = chop_if_long
|
||||||
@@ -347,3 +348,4 @@ resharper_csharp_place_type_constraints_on_same_line = false
|
|||||||
resharper_csharp_wrap_before_extends_colon = true
|
resharper_csharp_wrap_before_extends_colon = true
|
||||||
resharper_csharp_place_constructor_initializer_on_same_line = false
|
resharper_csharp_place_constructor_initializer_on_same_line = false
|
||||||
resharper_force_attribute_style = separate
|
resharper_force_attribute_style = separate
|
||||||
|
resharper_braces_for_ifelse = required_for_multiline
|
||||||
|
@@ -63,8 +63,10 @@ public class ReplacementBuilder
|
|||||||
{
|
{
|
||||||
var to = TimeZoneInfo.Local;
|
var to = TimeZoneInfo.Local;
|
||||||
if (g is not null)
|
if (g is not null)
|
||||||
|
{
|
||||||
if (GuildTimezoneService.AllServices.TryGetValue(client.CurrentUser.Id, out var tz))
|
if (GuildTimezoneService.AllServices.TryGetValue(client.CurrentUser.Id, out var tz))
|
||||||
to = tz.GetTimeZoneOrDefault(g.Id) ?? TimeZoneInfo.Local;
|
to = tz.GetTimeZoneOrDefault(g.Id) ?? TimeZoneInfo.Local;
|
||||||
|
}
|
||||||
|
|
||||||
return TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.Utc, to).ToString("HH:mm ")
|
return TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.Utc, to).ToString("HH:mm ")
|
||||||
+ to.StandardName.GetInitials();
|
+ to.StandardName.GetInitials();
|
||||||
|
@@ -214,8 +214,7 @@ public partial class Administration
|
|||||||
{
|
{
|
||||||
user ??= (IGuildUser)ctx.User;
|
user ??= (IGuildUser)ctx.User;
|
||||||
|
|
||||||
var channel = await user.CreateDMChannelAsync();
|
var success = await _service.GreetDmTest(user);
|
||||||
var success = await _service.GreetDmTest(channel, user);
|
|
||||||
if (success)
|
if (success)
|
||||||
await ctx.OkAsync();
|
await ctx.OkAsync();
|
||||||
else
|
else
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
using NadekoBot.Db;
|
using NadekoBot.Db;
|
||||||
using NadekoBot.Services.Database.Models;
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System.Threading.Channels;
|
||||||
|
|
||||||
namespace NadekoBot.Services;
|
namespace NadekoBot.Services;
|
||||||
|
|
||||||
public class GreetService : INService
|
public class GreetService : INService, IReadyExecutor
|
||||||
{
|
{
|
||||||
public bool GroupGreets
|
public bool GroupGreets
|
||||||
=> _bss.Data.GroupGreets;
|
=> _bss.Data.GroupGreets;
|
||||||
@@ -38,6 +40,17 @@ public class GreetService : INService
|
|||||||
_client.GuildMemberUpdated += ClientOnGuildMemberUpdated;
|
_client.GuildMemberUpdated += ClientOnGuildMemberUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task OnReadyAsync()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var (conf, user, compl) = await _greetDmQueue.Reader.ReadAsync();
|
||||||
|
var res = await GreetDmUserInternal(conf, user);
|
||||||
|
compl.TrySetResult(res);
|
||||||
|
await Task.Delay(2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Task ClientOnGuildMemberUpdated(Cacheable<SocketGuildUser, ulong> optOldUser, SocketGuildUser newUser)
|
private Task ClientOnGuildMemberUpdated(Cacheable<SocketGuildUser, ulong> optOldUser, SocketGuildUser newUser)
|
||||||
{
|
{
|
||||||
// if user is a new booster
|
// if user is a new booster
|
||||||
@@ -209,14 +222,33 @@ public class GreetService : INService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> GreetDmUser(GreetSettings conf, IDMChannel channel, IGuildUser user)
|
private readonly Channel<(GreetSettings, IGuildUser, TaskCompletionSource<bool>)> _greetDmQueue =
|
||||||
|
Channel.CreateBounded<(GreetSettings, IGuildUser, TaskCompletionSource<bool>)>(new BoundedChannelOptions(60)
|
||||||
|
{
|
||||||
|
// The limit of 60 users should be only hit when there's a raid. In that case
|
||||||
|
// probably the best thing to do is to drop newest (raiding) users
|
||||||
|
FullMode = BoundedChannelFullMode.DropNewest
|
||||||
|
});
|
||||||
|
|
||||||
|
private async Task<bool> GreetDmUser(GreetSettings conf, IGuildUser user)
|
||||||
|
{
|
||||||
|
var completionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
await _greetDmQueue.Writer.WriteAsync((conf, user, completionSource));
|
||||||
|
return await completionSource.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<bool> GreetDmUserInternal(GreetSettings conf, IGuildUser user)
|
||||||
{
|
{
|
||||||
var rep = new ReplacementBuilder().WithDefault(user, channel, (SocketGuild)user.Guild, _client).Build();
|
|
||||||
|
|
||||||
var text = SmartText.CreateFrom(conf.DmGreetMessageText);
|
|
||||||
text = rep.Replace(text);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var rep = new ReplacementBuilder()
|
||||||
|
.WithUser(user)
|
||||||
|
.WithServer(_client, (SocketGuild)user.Guild)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var text = SmartText.CreateFrom(conf.DmGreetMessageText);
|
||||||
|
text = rep.Replace(text);
|
||||||
|
|
||||||
if (text is SmartPlainText pt)
|
if (text is SmartPlainText pt)
|
||||||
{
|
{
|
||||||
text = new SmartEmbedText() { PlainText = pt.Text };
|
text = new SmartEmbedText() { PlainText = pt.Text };
|
||||||
@@ -227,7 +259,7 @@ public class GreetService : INService
|
|||||||
Text = $"This message was sent from {user.Guild} server.", IconUrl = user.Guild.IconUrl
|
Text = $"This message was sent from {user.Guild} server.", IconUrl = user.Guild.IconUrl
|
||||||
};
|
};
|
||||||
|
|
||||||
await channel.SendAsync(text);
|
await user.SendAsync(text);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -277,9 +309,7 @@ public class GreetService : INService
|
|||||||
|
|
||||||
if (conf.SendDmGreetMessage)
|
if (conf.SendDmGreetMessage)
|
||||||
{
|
{
|
||||||
var channel = await user.CreateDMChannelAsync();
|
await GreetDmUser(conf, user);
|
||||||
|
|
||||||
if (channel is not null) await GreetDmUser(conf, channel, user);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -551,10 +581,10 @@ public class GreetService : INService
|
|||||||
return GreetUsers(conf, channel, user);
|
return GreetUsers(conf, channel, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> GreetDmTest(IDMChannel channel, IGuildUser user)
|
public Task<bool> GreetDmTest(IGuildUser user)
|
||||||
{
|
{
|
||||||
var conf = GetOrAddSettingsForGuild(user.GuildId);
|
var conf = GetOrAddSettingsForGuild(user.GuildId);
|
||||||
return GreetDmUser(conf, channel, user);
|
return GreetDmUser(conf, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
Reference in New Issue
Block a user