Beispiel #1
0
        private static void BotActivityChangeCallback(object?_)
        {
            if (_ is TheGodfatherBot bot)
            {
                if (bot.Client is null || bot.Client.CurrentUser is null)
                {
                    Log.Error("BotActivityChangeCallback detected null client/user - this should not happen but is not nececarily an error");
                    return;
                }

                BotActivityService bas = bot.Services.GetRequiredService <BotActivityService>();
                if (!bas.StatusRotationEnabled)
                {
                    return;
                }

                try {
                    BotStatus?status = bas.GetRandomStatus();
                    if (status is null)
                    {
                        Log.Warning("No extra bot statuses present in the database.");
                    }

                    DiscordActivity activity = status is { }
                        ? new DiscordActivity(status.Status, status.Activity)
                        : new DiscordActivity($"@{bot.Client?.CurrentUser.Username} help", ActivityType.Playing);

                    AsyncExecutionService async = bot.Services.GetRequiredService <AsyncExecutionService>();
                    async.Execute(bot.Client !.UpdateStatusAsync(activity));
                    Log.Debug("Changed bot status to {ActivityType} {ActivityName}", activity.ActivityType, activity.Name);
                } catch (Exception e) {
Beispiel #2
0
 public SchedulingService(DbContextBuilder dbb, DiscordShardedClient client, LocalizationService lcs, AsyncExecutionService async, bool start = true)
 {
     this.client         = client;
     this.dbb            = dbb;
     this.lcs            = lcs;
     this.async          = async;
     this.tasks          = new ConcurrentDictionary <int, ScheduledTaskExecutor>();
     this.reminders      = new ConcurrentDictionary <int, ScheduledTaskExecutor>();
     this.LastReloadTime = DateTimeOffset.Now;
     this.ReloadSpan     = TimeSpan.FromMinutes(5);
     if (start)
     {
         this.Start();
     }
 }