blob: 2b8de814efd7948393bf37a72a68bef9199db440 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#pragma once
#include <chrono>
#include <optional>
#include <sol/sol.hpp>
#include <string>
#include "../utils/chrono.hpp"
#include "database.hpp"
namespace bot::schemas {
class User {
public:
User(const db::DatabaseRow &row) {
this->id = std::stoi(row.at("id"));
this->alias_id = std::stoi(row.at("alias_id"));
this->alias_name = row.at("alias_name");
this->joined_at =
utils::chrono::string_to_time_point(row.at("joined_at"));
if (!row.at("opted_out_at").empty()) {
this->opted_out_at =
utils::chrono::string_to_time_point(row.at("opted_out_at"));
}
}
~User() = default;
const int &get_id() const { return this->id; }
const int &get_alias_id() const { return this->alias_id; }
const std::string &get_alias_name() const { return this->alias_name; }
void set_alias_name(const std::string &alias_name) {
this->alias_name = alias_name;
}
const std::chrono::system_clock::time_point &get_joined_at() const {
return this->joined_at;
}
const std::optional<std::chrono::system_clock::time_point> &
get_opted_out_at() const {
return this->opted_out_at;
}
sol::table as_lua_table(std::shared_ptr<sol::state> luaState) const;
private:
int id, alias_id;
std::string alias_name;
std::chrono::system_clock::time_point joined_at;
std::optional<std::chrono::system_clock::time_point> opted_out_at;
};
enum PermissionLevel {
SUSPENDED,
USER,
VIP,
MODERATOR,
BROADCASTER,
TRUSTED = 50
};
class UserRights {
public:
UserRights(const db::DatabaseRow &row) {
this->id = std::stoi(row.at("id"));
this->user_id = std::stoi(row.at("user_id"));
this->channel_id = std::stoi(row.at("channel_id"));
this->level = static_cast<PermissionLevel>(std::stoi(row.at("level")));
}
~UserRights() = default;
const int &get_id() const { return this->id; }
const int &get_user_id() const { return this->user_id; }
const int &get_channel_id() const { return this->channel_id; }
const PermissionLevel &get_level() const { return this->level; }
void set_level(PermissionLevel level) { this->level = level; }
sol::table as_lua_table(std::shared_ptr<sol::state> luaState) const;
private:
int id, user_id, channel_id;
PermissionLevel level;
};
}
|