-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.cpp
142 lines (110 loc) · 3.95 KB
/
bot.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma warning(disable:4996)
#include <iostream>
#include <string>
#include <ctime>
#include <sapi.h>
#include <ctime>
#include <thread> // std::this_thread::sleep_for
#include <chrono>
using namespace std;
int HOUR, SEC, MIN, Min, Sec, Hour;
class RED {
private:
string const& s;
public:
RED(string const& s) : s(s) {}
friend ostream& operator<<(ostream& os, RED const& b) {
os << "\033[31m" << b.s << "\033[0m";
return os;
}
};
void gettime() {
time_t currentTime;
struct tm* localTime;
time(¤tTime); // Get the current time
localTime = localtime(¤tTime); // Convert the current time to the local time
Hour = localTime->tm_hour;
Min = localTime->tm_min;
Sec = localTime->tm_sec;
std::cout << "The current time is : " << Hour << ":" << Min << ":" << Sec << std::endl;
HOUR = 23 - Hour;
MIN = 60 - Min;
SEC = 60 - Sec;
if (HOUR >= 0)
std::cout << RED("2021 is in exactly : ");
else
cout << "It s been exactly ";
cout << HOUR << ":" << MIN << ":" << SEC ;
if (!(HOUR >= 0))
cout << " since we hit 2021";
}
int act() {
time_t currentTime;
struct tm* localTime;
time(¤tTime); // Get the current time
localTime = localtime(¤tTime);
Sec = localTime->tm_sec;
return Sec;
}
int main(int argc, char* argv[])
{
bool ok = 0;
while (true) {
ISpVoice* pVoice = NULL;
if (FAILED(::CoInitialize(NULL)))
return FALSE;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void**)&pVoice);
if (SUCCEEDED(hr))
{
if (ok) {
for (int i = 0; i < 5; ++i)
hr = pVoice->Speak(L"houraaaaaaa", 0, NULL);
for (int i = 0; i < 5; i++)
hr = pVoice->Speak(L"HAPPY NEW YEAR WE ARE IN 2021 ", 0, NULL);
}
gettime();
if (HOUR >= 0) {
hr = pVoice->Speak(L"2021 is in exactly", 0, NULL);
std::wstring input = std::to_wstring(HOUR) + L" hour";
hr = pVoice->Speak(input.c_str(), 0, NULL);
std::wstring input1 = std::to_wstring(MIN) + L" minutes and";
hr = pVoice->Speak(input1.c_str(), 0, NULL);
std::wstring input2 = std::to_wstring(SEC) + L" seconds";
hr = pVoice->Speak(input2.c_str(), 0, NULL);
hr = pVoice->Speak(L"HAPPY NEW YEAR!!!", 0, NULL);
pVoice->Release();
pVoice = NULL;
}
else {
hr = pVoice->Speak(L"HAPPY NEW YEAR!!! It has been ", 0, NULL);
std::wstring input = std::to_wstring(HOUR) + L" hour";
hr = pVoice->Speak(input.c_str(), 0, NULL);
std::wstring input1 = std::to_wstring(Min) + L" minutes and";
hr = pVoice->Speak(input1.c_str(), 0, NULL);
std::wstring input2 = std::to_wstring(Sec) + L" seconds";
hr = pVoice->Speak(input2.c_str(), 0, NULL);
hr = pVoice->Speak(L"secondes since we hit 2021. Once again Happy New Year! ", 0, NULL);
}
}
::CoUninitialize();
gettime();
if (ok == 0) {
if (Min < 59 and Min >= 2)
std::this_thread::sleep_for(std::chrono::seconds(45));
else {
if (Min == 59) {
while (true) {
int sec = act();
std::wstring input3 = std::to_wstring(sec) + L"";
hr = pVoice->Speak(input3.c_str(), 0, NULL);
if (sec == 0 or sec == 1 or sec == 2)
break;
}
ok = 1;
}
}
}
else
std::this_thread::sleep_for(std::chrono::seconds(60));
}
}