Exemplo n.º 1
0
        public static async Task <IReadOnlyDictionary <int, SendMessageTaskInfo> > GetAllRemindersAsync(this DBService db)
        {
            var tasks = new Dictionary <int, SendMessageTaskInfo>();

            await db.ExecuteCommandAsync(async (cmd) => {
                cmd.CommandText = "SELECT id, uid, cid, execution_time, message, repeat, interval FROM gf.reminders;";

                using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false)) {
                    while (await reader.ReadAsync().ConfigureAwait(false))
                    {
                        int id            = (int)reader["id"];
                        ulong cid         = reader["cid"] is DBNull ? 0 : (ulong)(long)reader["cid"];
                        ulong uid         = reader["uid"] is DBNull ? 0 : (ulong)(long)reader["uid"];
                        string message    = reader["message"] is DBNull ? null : (string)reader["message"];
                        bool repeat       = (bool)reader["repeat"];
                        var exectime      = (DateTime)reader["execution_time"];
                        TimeSpan?interval = reader["interval"] is DBNull ? (TimeSpan?)null : (TimeSpan)reader["interval"];
                        tasks.Add(id, new SendMessageTaskInfo(cid, uid, message, exectime, repeat, interval));
                    }
                }
            });

            return(new ReadOnlyDictionary <int, SendMessageTaskInfo>(tasks));
        }
Exemplo n.º 2
0
        public static async Task <IReadOnlyDictionary <int, SavedTaskInfo> > GetAllSavedTasksAsync(this DBService db)
        {
            var tasks = new Dictionary <int, SavedTaskInfo>();

            await db.ExecuteCommandAsync(async (cmd) => {
                cmd.CommandText = "SELECT type, id, gid, uid, rid, execution_time FROM gf.saved_tasks;";

                using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false)) {
                    while (await reader.ReadAsync().ConfigureAwait(false))
                    {
                        int id       = (int)reader["id"];
                        ulong gid    = reader["gid"] is DBNull ? 0 : (ulong)(long)reader["gid"];
                        ulong uid    = reader["uid"] is DBNull ? 0 : (ulong)(long)reader["uid"];
                        ulong rid    = reader["rid"] is DBNull ? 0 : (ulong)(long)reader["rid"];
                        var exectime = (DateTime)reader["execution_time"];
                        switch ((SavedTaskType)(short)reader["type"])
                        {
                        case SavedTaskType.Unban:
                            tasks.Add(id, new UnbanTaskInfo(gid, uid, exectime));
                            break;

                        case SavedTaskType.Unmute:
                            tasks.Add(id, new UnmuteTaskInfo(gid, uid, rid, exectime));
                            break;
                        }
                    }
                }
            });

            return(new ReadOnlyDictionary <int, SavedTaskInfo>(tasks));
        }
Exemplo n.º 3
0
 public static Task RemoveSavedTaskAsync(this DBService db, int id)
 => RemoveSavedTaskAsync(db, "saved_tasks", id);
Exemplo n.º 4
0
 public static Task RemoveReminderAsync(this DBService db, int id)
 => RemoveSavedTaskAsync(db, "reminders", id);
Exemplo n.º 5
0
        public static async Task <IReadOnlyDictionary <ulong, CachedGuildConfig> > GetAllCachedGuildConfigurationsAsync(this DBService db)
        {
            var dict = new Dictionary <ulong, CachedGuildConfig>();

            await db.ExecuteCommandAsync(async (cmd) => {
                cmd.CommandText = "SELECT * FROM gf.guild_cfg;";

                using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false)) {
                    while (await reader.ReadAsync().ConfigureAwait(false))
                    {
                        dict.Add((ulong)(long)reader["gid"], new CachedGuildConfig()
                        {
                            Currency           = reader["currency"] is DBNull ? null : (string)reader["currency"],
                            LinkfilterSettings = new LinkfilterSettings()
                            {
                                Enabled                 = (bool)reader["linkfilter_enabled"],
                                BlockBooterWebsites     = (bool)reader["linkfilter_booters"],
                                BlockDiscordInvites     = (bool)reader["linkfilter_invites"],
                                BlockDisturbingWebsites = (bool)reader["linkfilter_disturbing"],
                                BlockIpLoggingWebsites  = (bool)reader["linkfilter_iploggers"],
                                BlockUrlShorteners      = (bool)reader["linkfilter_shorteners"],
                            },
                            LogChannelId      = (ulong)(long)reader["log_cid"],
                            Prefix            = reader["prefix"] is DBNull ? null : (string)reader["prefix"],
                            RatelimitSettings = new RatelimitSettings()
                            {
                                Enabled     = (bool)reader["ratelimit_enabled"],
                                Action      = (PunishmentActionType)(short)reader["ratelimit_action"],
                                Sensitivity = (short)reader["ratelimit_sens"],
                            },
                            ReactionResponse   = (bool)reader["silent_respond"],
                            SuggestionsEnabled = (bool)reader["suggestions_enabled"],
                        });
                    }
                }
            });

            return(new ReadOnlyDictionary <ulong, CachedGuildConfig>(dict));
        }