Example #1
0
            public async Task SetGame(ActivityType type, [Remainder] string game = null)
            {
                var rep = new ReplacementBuilder()
                          .WithDefault(Context)
                          .Build();

                await _bot.SetGameAsync(game == null?game : rep.Replace(game), type).ConfigureAwait(false);

                await ReplyConfirmLocalized("set_game").ConfigureAwait(false);
            }
Example #2
0
        private async void RotatingStatuses(object objState)
        {
            try
            {
                var state = (TimerState)objState;

                if (!_bss.Data.RotateStatuses)
                {
                    return;
                }

                IReadOnlyList <RotatingPlayingStatus> rotatingStatuses;
                using (var uow = _db.GetDbContext())
                {
                    rotatingStatuses = uow._context.RotatingStatus
                                       .AsNoTracking()
                                       .OrderBy(x => x.Id)
                                       .ToList();
                }

                if (rotatingStatuses.Count == 0)
                {
                    return;
                }

                var playingStatus = state.Index >= rotatingStatuses.Count
                    ? rotatingStatuses[state.Index = 0]
                    : rotatingStatuses[state.Index++];

                var statusText = _rep.Replace(playingStatus.Status);
                await _bot.SetGameAsync(statusText, playingStatus.Type);
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "Rotating playing status errored: {ErrorMessage}", ex.Message);
            }
        }
Example #3
0
        public PlayingRotateService(DiscordSocketClient client, IBotConfigProvider bcp,
                                    DbService db, IDataCache cache, NadekoBot bot, MusicService music)
        {
            _client = client;
            _bcp    = bcp;
            _db     = db;
            _log    = LogManager.GetCurrentClassLogger();
            _cache  = cache;

            if (client.ShardId == 0)
            {
                _rep = new ReplacementBuilder()
                       .WithClient(client)
                       .WithStats(client)
                       .WithMusic(music)
                       .Build();

                _t = new Timer(async(objState) =>
                {
                    try
                    {
                        bcp.Reload();

                        var state = (TimerState)objState;
                        if (!BotConfig.RotatingStatuses)
                        {
                            return;
                        }
                        if (state.Index >= BotConfig.RotatingStatusMessages.Count)
                        {
                            state.Index = 0;
                        }

                        if (!BotConfig.RotatingStatusMessages.Any())
                        {
                            return;
                        }
                        var status = BotConfig.RotatingStatusMessages[state.Index++].Status;
                        if (string.IsNullOrWhiteSpace(status))
                        {
                            return;
                        }

                        status = _rep.Replace(status);

                        try
                        {
                            await bot.SetGameAsync(status).ConfigureAwait(false);
                        }
                        catch (Exception ex)
                        {
                            _log.Warn(ex);
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Warn("Rotating playing status errored.\n" + ex);
                    }
                }, new TimerState(), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
            }
        }
Example #4
0
            public async Task SetGame(ActivityType type, [Remainder] string game = null)
            {
                await _bot.SetGameAsync(game, type).ConfigureAwait(false);

                await ReplyConfirmLocalized("set_game").ConfigureAwait(false);
            }