Example #1
0
 public async Task AddMessageActivity(IUserMessage message, uint activityScore, uint altScore)
 {
     if (!(message.Channel is IGuildChannel channel))
     {
         return;
     }
     using var db = data.GetContext();
     // I'll return to this later or something.
     await db.AddActivity(channel.GuildId, channel.Id, message.Author.Id, activityScore, altScore, DateTime.UtcNow);
 }
        private (List <T>, string) Getrep <T>()
        {
            var storagePath = DataContextFactory.GetContext();
            var items       = new List <T>();

            if (!storagePath.EndsWith(@"\"))
            {
                storagePath += @"\";
            }
            var entityType = typeof(T);
            var typeName   = entityType.Name;

            storagePath = $"{storagePath}{typeName}.xml";

            if (!File.Exists(storagePath))
            {
                throw new ConfigurationErrorsException(
                          "The directory attribute is required in order to use the XmlRepository via the configuration file.");
            }

            using var stream = new FileStream(storagePath, FileMode.Open);
            using var reader = new StreamReader(stream);
            var serializer = new XmlSerializer(typeof(List <T>));

            items = (List <T>)serializer.Deserialize(reader);

            return(items, storagePath);
        }
        /// <inheritdoc />
        public override IRepository <T> GetInstance <T>()
        {
            var(items, storagePath) = Getrep <T>();

            return(string.IsNullOrEmpty(DataContextFactory.GetContext())
                ? throw new ConfigurationErrorsException(
                       "The directory attribute is required in order to use the XmlRepository via the configuration file.")
                : new XmlRepository <T>(items, storagePath));
        }
        /// <inheritdoc />
        public override IRepository <T, TKey> GetInstance <T, TKey>()
        {
            var collection = DataContextFactory
                             .GetContext()
                             .GetDatabase(DataContextFactory.dbConfiguration.DatabaseName)
                             .GetCollection <T>(typeof(T).Name);

            return(new MongoDbRepository <T, TKey>(collection));
        }
Example #5
0
        public async Task HandleReactionAdd(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (reaction.User.IsSpecified && reaction.User.Value.IsBot)
            {
                return;
            }
            using var db = data.GetContext();
            var actionData = await db.GetAction(message.Id);

            if (actionData == null)
            {
                return;
            }
            var action = GetAction(actionData);

            if (action.ValidateEmote(reaction.Emote))
            {
                await action.ActionOn(actionData, reaction);
            }
        }
Example #6
0
 public async Task Kick(IGuildUser member, ulong moderator, string?reason)
 {
     using var db = data.GetContext();
     await Task.WhenAll(
         db.AddModerationAction(
             guild: member.GuildId,
             member: member.Id,
             moderator: moderator,
             since: DateTime.UtcNow,
             type: (byte)ModerationType.Kick,
             reason: reason
             ),
         member.KickAsync()
         );
 }
Example #7
0
        public ActionResult <Location> Get(ODataQueryOptions <Location> opts, string format = "")
        {
            // If one attempts to access /odata/locations?$apply=groupby((PersonResponsible))
            // to this context, you get
            // System.NotSupportedException: Comparison operators not supported
            // for type 'Syste m.Collections.Generic.Dictionary`2[System.String, System.Object]'.
            var table = DataContextFactory.GetContext().GetTable <Location>();

            return(Ok(opts.ApplyTo(table)));

            // Comment the above and uncomment the below to show
            // $apply=groupby((PersonResponsible)) working correctly.

            //var locations = new List<Location>
            //{
            //    new Location {LocationId = 1, Name = "Loc1", PersonResponsible = "foo"},
            //    new Location {LocationId = 2, Name = "loc2", PersonResponsible = "bar"},
            //    new Location {LocationId = 3, Name = "loc3", PersonResponsible = "foo"}
            //};
            //return Ok(opts.ApplyTo(locations.AsQueryable()));
        }
        /// <inheritdoc />
        public override IRepository <T, TKey> GetInstance <T, TKey>()
        {
            var context = DataContextFactory.GetContext();

            return(new RavenDbRepository <T, TKey>(context));
        }
 /// <inheritdoc />
 public override ICompoundKeyRepository <T, TKey, TKey2, TKey3> GetInstance <T, TKey, TKey2, TKey3>()
 {
     return(new EfRepository <T, TKey, TKey2, TKey3>(DataContextFactory.GetContext()));
 }
 /// <inheritdoc />
 public override IRepository <T, TKey> GetInstance <T, TKey>()
 {
     return(new EfRepository <T, TKey>(DataContextFactory.GetContext()));
 }
Example #11
0
 public async Task <TopicData?> GetTopic(IGuildChannel channel)
 {
     using var db = data.GetContext();
     return(await db.GetTopicByChannel(channel.GuildId, channel.Id));
 }
Example #12
0
 public async Task ClearPins(IMessageChannel channel)
 {
     using (var db = data.GetContext()) {
         await db.ClearPins(channel.Id);
     }
 }