コード例 #1
0
ファイル: PlayingRotateService.cs プロジェクト: Slamerz/DmC
        public PlayingRotateService(DiscordSocketClient client, IBotConfigProvider bcp,
                                    DbService db, IDataCache cache, EvilMortyBot bot, MusicService music)
        {
            _client = client;
            _bcp    = bcp;
            _db     = db;
            _log    = LogManager.GetCurrentClassLogger();
            _cache  = cache;

            if (client.ShardId == 0)
            {
                _rep = new ReplacementBuilder()
                       .WithClient(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 msg    = BotConfig.RotatingStatusMessages[state.Index++];
                        var status = msg.Status;
                        if (string.IsNullOrWhiteSpace(status))
                        {
                            return;
                        }

                        status = _rep.Replace(status);

                        try
                        {
                            await bot.SetGameAsync(status, msg.Type).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));
            }
        }
コード例 #2
0
ファイル: SelfCommands.cs プロジェクト: Slamerz/DmC
            public async Task SetGame(ActivityType type, [Remainder] string game = null)
            {
                await _bot.SetGameAsync(game, type).ConfigureAwait(false);

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