Exemple #1
0
        public bool AddFactoid(string user, string item, bool isAre, string value, bool replaceExisting)
        {
            if (replaceExisting)
            {
                ForgetFactoid(user, item);
            }

            var newFactoid = new Factoid()
            {
                User      = user,
                Item      = item,
                IsAre     = isAre,
                Value     = value,
                Timestamp = DateTime.UtcNow,
            };

            _Db.Factoid.Add(newFactoid);

            var history = new FactoidHistory()
            {
                Item      = item,
                Value     = value,
                User      = user,
                Timestamp = DateTime.UtcNow
            };

            _Db.FactoidHistory.Add(history);

            _Db.SaveChanges();

            return(true);
        }
Exemple #2
0
        public Factoid Add(Factoid newFactoid)
        {
            if (newFactoid == null)
            {
                return(null);
            }

            factoids.Add(newFactoid);
            newFactoid.Id = factoids.Max(r => r.Id) + 1;
            return(newFactoid);
        }
Exemple #3
0
        private void CreateFactoid(string title, string text)
        {
            var factoid = new Factoid();

            factoid.Details              = new Factoid.FactoidDetailsTab();
            factoid.Details.Image        = _image;
            factoid.Details.FactoidTitle = title;           //new DataTypes.BuiltIn.Textstring() { Value = title };
            factoid.Details.FactoidText  = text;            //new DataTypes.BuiltIn.Textstring() { Value = text };
            factoid.NodeDetails.Name     = factoid.Details.FactoidTitle.Value.Truncate(10);
            factoid.Persist(_factoidFolder?.NodeDetails?.UmbracoId ?? -1, publish: true);
            _factoids.Add(factoid);
        }
        private async Task SaveOrUpdate(Factoid factoid, CancellationToken cancellationToken)
        {
            if (factoid.Id == 0)
            {
                await _context.Factoids.AddAsync(factoid, cancellationToken);
            }
            else
            {
                _context.Factoids.Update(factoid);
            }

            await _context.SaveChangesAsync(cancellationToken);
        }
Exemple #5
0
        public Factoid Update(Factoid updatedFactoid)
        {
            if (updatedFactoid == null)
            {
                return(null);
            }

            var factoid = factoids.SingleOrDefault(r => r.Id == updatedFactoid.Id);

            if (factoid != null)
            {
                factoid.Item     = updatedFactoid.Item;
                factoid.IsAre    = updatedFactoid.IsAre;
                factoid.Value    = updatedFactoid.Value;
                factoid.DateSet  = DateTime.UtcNow;
                factoid.IsLocked = updatedFactoid.IsLocked;
                factoid.LastSync = updatedFactoid.LastSync;
                factoid.Nick     = updatedFactoid.Nick;
            }
            return(factoid);
        }
        protected override async Task HandleMessageAsyncInternal(IrcPrivMessage request, CancellationToken cancellationToken)
        {
            var match = FactoidRegex.Match(request.Text);

            if (match.Success)
            {
                var command     = match.Groups[1].Value;
                var name        = match.Groups[2].Value;
                var description = match.Groups[3].Value;

                // We're adding a new factoid.
                if (description.Length > 0)
                {
                    var factoid = new Factoid
                    {
                        Description  = description,
                        Type         = command,
                        CreationDate = DateTime.UtcNow,
                        CreatedBy    = request.UserName,
                        Name         = name
                    };

                    await SaveOrUpdate(factoid, cancellationToken);
                    await SendResponse(request, "Factoid saved.");
                }

                // Otherwise we're looking up factoids by name/type.
                else
                {
                    var query = _context.Factoids
                                .Where(factoid => factoid.Type.ToLower() == command.ToLower() && factoid.Name.ToLower() == name.ToLower());

                    var matchingFactoids = query
                                           .OrderByDescending(factoid => factoid.CreationDate)
                                           .Take(FactDisplayCount)
                                           .ToList();

                    int count = matchingFactoids.Count;
                    if (count > 0)
                    {
                        // If we retrieved the limit, check so we can tell users if there's more facts they can't see.
                        // They'll have to hit the web UI for these.
                        if (count == FactDisplayCount)
                        {
                            count = query.Count();
                        }

                        var pluralization = (count == 1) ? string.Empty : "s";

                        var paginationDisplay = (count > FactDisplayCount)
                            ? $" (showing the first {FactDisplayCount})"
                            : string.Empty;

                        var factoidDisplay = matchingFactoids
                                             .Select(x => $"[{x.Description} at {x.CreationDate:MM/dd/yyyy H:mm:ss UTC} by {x.CreatedBy}]");

                        var response =
                            $"Found {count} factoid{pluralization} of type {command}{paginationDisplay} for {name}: {String.Join(", ", factoidDisplay)}";

                        await SendResponse(request, response);
                    }
                    else
                    {
                        await SendResponse(request, $"No factoids for {name} of type {command}");
                    }
                }
            }
        }
 private void CreateFactoid(string title, string text)
 {
     var factoid = new Factoid();
     factoid.Details = new Factoid.FactoidDetailsTab();
     factoid.Details.Image = _image;
     factoid.Details.FactoidTitle = title; //new DataTypes.BuiltIn.Textstring() { Value = title };
     factoid.Details.FactoidText = text; //new DataTypes.BuiltIn.Textstring() { Value = text };
     factoid.NodeDetails.Name = factoid.Details.FactoidTitle.Value.Truncate(10);
     factoid.Persist(_factoidFolder?.NodeDetails?.UmbracoId ?? -1, publish: true);
     _factoids.Add(factoid);
 }