static PlayingRotateCommands() { _log = LogManager.GetCurrentClassLogger(); RotatingStatusMessages = NadekoBot.BotConfig.RotatingStatusMessages; RotatingStatuses = NadekoBot.BotConfig.RotatingStatuses; _t = new Timer(async(_) => { var index = 0; try { if (!RotatingStatuses) { return; } else { if (index >= RotatingStatusMessages.Count) { index = 0; } if (!RotatingStatusMessages.Any()) { return; } var status = RotatingStatusMessages[index++].Status; if (string.IsNullOrWhiteSpace(status)) { return; } PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value())); var shards = NadekoBot.Client.Shards; for (int i = 0; i < shards.Count; i++) { ShardSpecificPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value(shards.ElementAt(i)))); try { await shards.ElementAt(i).SetGameAsync(status).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } } } } catch (Exception ex) { _log.Warn("Rotating playing status errored.\n" + ex); } }, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1)); }
//todo wtf is with this while(true) in constructor static PlayingRotateCommands() { _log = LogManager.GetCurrentClassLogger(); using (var uow = DbHandler.UnitOfWork()) { var conf = uow.BotConfig.GetOrCreate(); RotatingStatusMessages = conf.RotatingStatusMessages; RotatingStatuses = conf.RotatingStatuses; } var t = Task.Run(async() => { var index = 0; do { try { if (!RotatingStatuses) { continue; } else { if (index >= RotatingStatusMessages.Count) { index = 0; } if (!RotatingStatusMessages.Any()) { continue; } var status = RotatingStatusMessages[index++].Status; if (string.IsNullOrWhiteSpace(status)) { continue; } PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value())); await NadekoBot.Client.SetGame(status); } } catch (Exception ex) { _log.Warn("Rotating playing status errored.\n" + ex); } finally { await Task.Delay(TimeSpan.FromMinutes(1)); } } while (true); }); }
public PlayingRotateCommands() { _log = LogManager.GetCurrentClassLogger(); Task.Run(async() => { var index = 0; do { try { if (!RotatingStatuses) { continue; } else { if (index >= RotatingStatusMessages.Count) { index = 0; } if (!RotatingStatusMessages.Any()) { continue; } var status = RotatingStatusMessages[index++].Status; if (string.IsNullOrWhiteSpace(status)) { continue; } PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value())); await(await NadekoBot.Client.GetCurrentUserAsync()) .ModifyStatusAsync(mpp => mpp.Game = new Game(status)) .ConfigureAwait(false); } } catch (Exception ex) { _log.Warn("Rotating playing status errored.\n" + ex); } finally { await Task.Delay(15000); } } while (true); }); }