public DiscordHandler(string discordToken, MahCounter counter) { this._counter = counter; this._options = new Options(); this._client = this.GetClient(discordToken); this._client.MessageReceived += MessageReceivedAsync; this._client.StartAsync(); this._pipeline = new Pipeline <MessageContext>(); this._pipeline.Add(new ToggleMahConfirmHandler().HandleAsync); this._pipeline.Add(new AddMahsHandler().HandleAsync); this._pipeline.Add(new SetMahsHandler().HandleAsync); this._pipeline.Add(new GetMahsHandler().HandleAsync); this._pipeline.Add(new HelpHandler().HandleAsync); this._pipeline.Add(new MahHandler().HandleAsync); }
public async Task <MahCounter> GetCounterAsync() { if (_mahCounter != null) { return(_mahCounter); } var persistedCount = await File.ReadAllTextAsync(this._filePath); lock (lockObject) { if (_mahCounter != null) { return(_mahCounter); } _mahCounter = new MahCounter(int.Parse(persistedCount)); _mahCounter.OnCounterIncremented += this.PersistAsync; return(_mahCounter); } }
public Task PersistAsync(MahCounter counter) => File.WriteAllTextAsync(this._filePath, counter.Count.ToString());