Beispiel #1
0
        public override Task <bool> Invoke(ChatMessage message)
        {
            // Temporary fix to restrict command
            // TODO: Create proper permissions system
            if (!(message.IsModerator || message.IsBroadcaster))
            {
                return(Task.FromResult(false));
            }

            var counter = _counterService.GetCounter(_counterKey) ?? _counterService.AddCounter(_counterKey);

            switch (_arithmetic)
            {
            case Arithmetic.Addition:
                _counterService.AddCount(counter);
                break;

            case Arithmetic.Subtraction:
                _counterService.RemoveCount(counter);
                break;

            default:
                _twitchClient.SendMessage(message.Channel, "You must specify addition (+) or subtraction (-).");
                break;
            }

            _twitchClient.SendMessage(message.Channel,
                                      $"{counter.Name} adjusted. Current {counter.Name}: {counter.Count}");

            return(Task.FromResult(true));
        }
        public ItemCounterPartHandler(ICounterService counters, IAuthenticationService auth, IOrchardServices services)
        {
            OnRemoved<ItemCounterPart>((ctx, part) => counters.RemoveAllCounters(part.ContentItem.Id));

            OnGetDisplayShape<ItemCounterPart>((ctx, part) =>
            {
                var settings = part.Settings.GetModel<ItemCounterPartTypePartSettings>();
                var type = part.Record == null ? settings.Type : part.Type;

                // Incrementing visit counters here
                var user = auth.GetAuthenticatedUser();
                var site = services.WorkContext.CurrentSite;
                var countUser = 0;
                var countSite = 0;
                var countSession = 0;
                if (user != null){
                    countUser = ctx.DisplayType != "Detail" ? 
                        counters.GetCounter(part.ContentItem.Id, user.Id, CounterType.Visits, CounterStoreType.Database) 
                        : counters.Increment(part.ContentItem.Id, user.Id, CounterType.Visits, CounterStoreType.Database);
                }
                if (site != null){
                     countSite = ctx.DisplayType != "Detail" ?
                        counters.GetCounter(part.ContentItem.Id, site.Id, CounterType.Visits, CounterStoreType.Database)
                        : counters.Increment(part.ContentItem.Id, site.Id, CounterType.Visits, CounterStoreType.Database);
                }
                if (site != null && services.WorkContext.HttpContext != null){
                    countSession = ctx.DisplayType != "Detail" ?
                        counters.GetCounter(part.ContentItem.Id, site.Id, CounterType.Visits, CounterStoreType.Session)
                        : counters.Increment(part.ContentItem.Id, site.Id, CounterType.Visits, CounterStoreType.Session);
                }

                /* Setting appropriate counter */
                part.Count = (type == VisitCounterType.PerSite)
                                 ? countSite
                                 : (type == VisitCounterType.PerUser &&
                                    user != null)
                                       ? countUser
                                       : countSession;
            });
        }
Beispiel #3
0
        public override async Task <bool> Invoke(ChatMessage message)
        {
            var game = await _twitchApiHelper.GetStreamGame(message.Channel);

            if (game == null)
            {
                _twitchClient.SendMessage(message.Channel,
                                          "The streamer either is not online or does not have a game set!");

                return(await Task.FromResult(false));
            }

            var counter = _counterService.GetCounter($"{game.Name}Wins");

            _twitchClient.SendMessage(message.Channel,
                                      counter == null
                    ? $"There are no wins recorded for {game.Name}!"
                    : $"Current {game.Name} Wins: {counter.Count}");

            return(await Task.FromResult(true));
        }
Beispiel #4
0
 public void Index()
 {
     PropertyBag.Add("hiraganaCounter", counterService.GetCounter("hiragana"));
     PropertyBag.Add("katakanaCounter", counterService.GetCounter("katakana"));
 }
Beispiel #5
0
 public async Task <CounterInfo> GetCounter()
 {
     return(await _counterService.GetCounter(_securityService.GetUserID(HttpContext)));
 }