using System.Text;
namespace RegexBot.Modules.EntryTimeRole;
///
/// Automatically sets a role onto users entering the guild after a predefined amount of time.
///
[RegexbotModule]
public class EntryTimeRole : RegexbotModule {
readonly Task _workerTask;
readonly CancellationTokenSource _workerTaskToken; // TODO make use of this when possible
public EntryTimeRole(RegexbotClient bot) : base(bot) {
DiscordClient.UserJoined += DiscordClient_UserJoined;
DiscordClient.UserLeft += DiscordClient_UserLeft;
_workerTaskToken = new CancellationTokenSource();
_workerTask = Task.Factory.StartNew(RoleApplyWorker, _workerTaskToken.Token,
TaskCreationOptions.LongRunning, TaskScheduler.Default);
}
private Task DiscordClient_UserJoined(SocketGuildUser arg) {
GetGuildState(arg.Guild.Id)?.WaitlistAdd(arg.Id);
return Task.CompletedTask;
}
private Task DiscordClient_UserLeft(SocketGuild guild, SocketUser user) {
GetGuildState(guild.Id)?.WaitlistRemove(user.Id);
return Task.CompletedTask;
}
public override Task