Beispiel #1
0
        public static DatabaseSavedTask FromSavedTaskInfo(SavedTaskInfo tinfo)
        {
            var dbti = new DatabaseSavedTask()
            {
                ExecutionTime = tinfo.ExecutionTime.UtcDateTime
            };

            switch (tinfo)
            {
            case UnbanTaskInfo ubti:
                dbti.GuildId = ubti.GuildId;
                dbti.UserId  = ubti.UnbanId;
                dbti.Type    = SavedTaskType.Unban;
                break;

            case UnmuteTaskInfo umti:
                dbti.GuildId = umti.GuildId;
                dbti.UserId  = umti.UserId;
                dbti.RoleId  = umti.MuteRoleId;
                dbti.Type    = SavedTaskType.Unmute;
                break;

            default:
                return(null);
            }

            return(dbti);
        }
Beispiel #2
0
        public static async Task <int> AddSavedTaskAsync(this DBService db, SavedTaskInfo info)
        {
            int id = 0;

            await db.ExecuteCommandAsync(async (cmd) => {
                switch (info)
                {
                case SendMessageTaskInfo smi:
                    cmd.CommandText = "INSERT INTO gf.reminders(uid, cid, execution_time, message, repeat, interval) VALUES (@uid, @cid, @execution_time, @message, @repeat, @interval) RETURNING id;";
                    cmd.Parameters.Add(new NpgsqlParameter <long>("uid", (long)smi.InitiatorId));
                    cmd.Parameters.Add(new NpgsqlParameter <long>("cid", (long)smi.ChannelId));
                    cmd.Parameters.Add(new NpgsqlParameter <string>("message", smi.Message));
                    cmd.Parameters.Add(new NpgsqlParameter <bool>("repeat", smi.IsRepeating));
                    cmd.Parameters.Add(new NpgsqlParameter <TimeSpan>("interval", smi.RepeatingInterval));
                    break;

                case UnbanTaskInfo ubi:
                    cmd.CommandText = "INSERT INTO gf.saved_tasks(type, uid, gid, execution_time) VALUES (@type, @uid, @gid, @execution_time) RETURNING id;";
                    cmd.Parameters.Add(new NpgsqlParameter <short>("type", (short)SavedTaskType.Unban));
                    cmd.Parameters.Add(new NpgsqlParameter <long>("gid", (long)ubi.GuildId));
                    cmd.Parameters.Add(new NpgsqlParameter <long>("uid", (long)ubi.UnbanId));
                    break;

                case UnmuteTaskInfo umi:
                    cmd.CommandText = "INSERT INTO gf.saved_tasks(type, uid, gid, rid, execution_time) VALUES (@type, @uid, @gid, @rid, @execution_time) RETURNING id;";
                    cmd.Parameters.Add(new NpgsqlParameter <short>("type", (short)SavedTaskType.Unmute));
                    cmd.Parameters.Add(new NpgsqlParameter <long>("gid", (long)umi.GuildId));
                    cmd.Parameters.Add(new NpgsqlParameter <long>("uid", (long)umi.UserId));
                    cmd.Parameters.Add(new NpgsqlParameter <long>("rid", (long)umi.MuteRoleId));
                    break;

                default:
                    throw new ArgumentException("Unknown saved task info type!", nameof(info));
                }
                cmd.Parameters.AddWithValue("execution_time", NpgsqlDbType.TimestampTz, info.ExecutionTime);

                object res = await cmd.ExecuteScalarAsync().ConfigureAwait(false);
                if (res != null && !(res is DBNull))
                {
                    id = (int)res;
                }
            });

            return(id);
        }
Beispiel #3
0
        public static DatabaseReminder FromSavedTaskInfo(SavedTaskInfo tinfo)
        {
            var smti = tinfo as SendMessageTaskInfo;

            if (smti is null)
            {
                return(null);
            }

            var dbr = new DatabaseReminder {
                ChannelId        = smti.ChannelId,
                ExecutionTime    = tinfo.ExecutionTime.UtcDateTime,
                IsRepeating      = smti.IsRepeating,
                Message          = smti.Message,
                RepeatIntervalDb = smti.RepeatingInterval,
                UserId           = smti.InitiatorId
            };

            return(dbr);
        }
Beispiel #4
0
        public static DatabaseReminder FromSavedTaskInfo(SavedTaskInfo tinfo)
        {
            var minfo = tinfo as SendMessageTaskInfo;

            if (minfo is null)
            {
                return(null);
            }

            var reminder = new DatabaseReminder
            {
                ChannelId        = minfo.ChannelId,
                ExecutionTime    = tinfo.ExecutionTime.UtcDateTime,
                IsRepeating      = minfo.IsRepeating,
                Message          = minfo.Message,
                RepeatIntervalDb = minfo.RepeatingInterval,
                UserId           = minfo.InitiatorId
            };

            return(reminder);
        }