-
Notifications
You must be signed in to change notification settings - Fork 0
/
other.cpp
77 lines (69 loc) · 1.2 KB
/
other.cpp
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
#include "common.h"
#include <unistd.h>
#include <ctime>
void other::sleep(int ms)
{
usleep(ms*1000);
}
time_t td;
void other::startTime()
{
td=time(NULL);
}
string other::getTime()
{
string str = ctime(&td);
str.resize(str.size()-1);
return str;
}
string other::getRealTime()
{
time_t temp = time(NULL);
string str = ctime(&temp);
str.resize(str.size()-1);
return str;
}
string other::getTime(time_t temp)
{
string str = ctime(&temp);
str.resize(str.size()-1);
return str;
}
string other::getId(message::msg msg)
{
string id;
if(msg.msg[6]["from"].is_null()) id = to_string((int)msg.msg[3]);
else id = msg.msg[6]["from"];
return id;
}
json other::jsonDifferenceArr(json j1, json j2)
{
json out;
for(unsigned int i1 = 0; i1 < j1.size(); i1++)
{
bool f = true;
for(unsigned int i2 = 0; i2 < j2.size(); i2++)
{
if(j1[i1]==j2[i2])
{
f = false;
break;
}
}
if(f) out.push_back(j1[i1]);
}
return out;
}
void other::fwds(json *in, json *out, unsigned int lvl)
{
for(auto i: *in)
{
json t;
t["msg"]=i["body"];
t["user_id"]=i["user_id"];
t["lvl"]=lvl;
out->push_back(t);
if(i["fwd_messages"].is_null())continue;
other::fwds(&i["fwd_messages"], out, lvl+1);
}
}