Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
 public Task PersistAsync(MahCounter counter) =>
 File.WriteAllTextAsync(this._filePath, counter.Count.ToString());