-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
202 lines (193 loc) · 6.05 KB
/
index.ts
File metadata and controls
202 lines (193 loc) · 6.05 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { Context, Snake } from "tgsnake";
// import fs from "fs";
import { Combine, MessageContext } from "tgsnake/lib/Context";
import moment from "moment-jalaali";
const bot = new Snake({
apiId: 16946914,
apiHash: "840e20c7fc0998b976d242a108d68784",
botToken: "5532535099:AAHK-lYwtgPNdBl59OwTbOPVg2T0chCURTQ",
});
//@ts-ignore
BigInt.prototype.toJSON = function() { return this.toString() }
type teamType = {
id: bigint;
name: string;
userId: string;
free: number;
};
let data: any = {};
let admins = [5487311601n];
let team: teamType[] = [];
const notif = () => {
let text =
"📅 " +
moment().format("jYYYY/jMM/jDD") +
"\n\n" +
"❌ افراد زیر گزارش کار را ارسال نکرده اند" +
"\n\n";
let text2 = "✅ افراد زیر گزارش کار را ارسال کرده اند" + "\n\n";
let text3 = "🆓 افراد زیر در مرخصی هستند" + "\n\n";
for (let v of team) {
if (v.free > 0) {
text3 += "👤 " + v.name + "\n" + v.free + "روز باقی مانده" + "\n\n";
continue;
}
let has: any = false;
for (let v2 of data[moment().format("jYYYY/jMM/jDD")] || []) {
if (v.userId == v2.user) {
has = v2;
break;
}
}
if (!has) {
text += "👤 @" + v.userId + "\n\n";
} else {
text2 += "👤 " + v.name + "\n" + has.text + "\n\n";
}
}
bot.telegram.sendMessage(-1001778747367n, text + text2 + text3);
};
let teamAction = [
{
text: "set",
callBack: (ctx: Combine<MessageContext, {}>) => {
if (
data[moment().format("jYYYY/jMM/jDD")]?.find(
(x: any) => x.user == ctx.from.username
)
) {
return ctx.reply(
"شما قبلا گزارش روزانه خود را ثبت کرده اید، برای ثبت مجدد ابتدا گزارش را حذف کنید"
);
}
if (!data[moment().format("jYYYY/jMM/jDD")]) {
data[moment().format("jYYYY/jMM/jDD")] = [];
}
data[moment().format("jYYYY/jMM/jDD")].push({
user: ctx.from.username,
text: ctx.text?.replace("set", ""),
});
ctx.reply("باتشکر از شما، گزارش روزانه شما ثبت گردید");
},
},
{
text: "tag",
callBack: (ctx: Combine<MessageContext, {}>) => {
let txt = "کاربر " + ctx.from.firstName + " شما را منشن کرده است 🔊\n\n";
let users = team.filter((x) => x.id != ctx.from.id);
for (let v of users) {
txt += "👤 @" + v.userId + "\n";
}
ctx.telegram.sendMessage(ctx.chat.id, txt);
},
},
{
text: "delete",
callBack: (ctx: Combine<MessageContext, {}>) => {
if (!data[moment().format("jYYYY/jMM/jDD")]) {
data[moment().format("jYYYY/jMM/jDD")] = [];
}
data[moment().format("jYYYY/jMM/jDD")] = data[
moment().format("jYYYY/jMM/jDD")
].filter((x: any) => x.user != ctx.from.username);
ctx.reply("گزارش امروز شما حذف گردید");
},
},
{
text: "list",
callBack: (ctx: Combine<MessageContext, {}>) => {
let dataForSend = "📅 " + moment().format("jYYYY/jMM/jDD") + "\n\n";
for (let v of data[moment().format("jYYYY/jMM/jDD")]) {
v.name = team.find((x) => x.userId == v.user)?.name;
dataForSend += "👤 " + v.name + "\n" + v.text + "\n\n";
}
ctx.reply(dataForSend);
},
},
];
let adminAction = [
{
text: "add",
callBack: (ctx: Combine<MessageContext, {}>) => {
team.push({
id: ctx.replyToMessage?.from.id!,
name: ctx.replyToMessage?.from.firstName!,
userId: ctx.replyToMessage?.from.username!,
free: 0,
});
ctx.reply("به اعضای تیم اضافه گردید");
},
},
{
text: "remove",
callBack: (ctx: Combine<MessageContext, {}>) => {
team = team.filter((v) => v.id != ctx.replyToMessage?.from.id);
ctx.reply("از اعضای تیم حذف گردید");
},
},
{
text: "free",
callBack: (ctx: Combine<MessageContext, {}>) => {
team[team.findIndex((v) => v.id == ctx.replyToMessage?.from.id)].free =
Number(ctx.text?.replace("free", "").trim());
ctx.reply("مرخصی ثبت شد");
},
},
{
text: "addA",
callBack: (ctx: Combine<MessageContext, {}>) => {
admins.push(ctx.replyToMessage?.from.id!);
ctx.reply("به مدیران تیم اضافه گردید");
},
},
{
text: "removeA",
callBack: (ctx: Combine<MessageContext, {}>) => {
admins.push(ctx.replyToMessage?.from.id!);
ctx.reply("از مدیران تیم حذف گردید");
},
},
];
bot.on("message", (ctx) => {
if (
adminAction.find((x) => ctx.text?.startsWith(x.text)) &&
admins.includes(ctx.from.id) &&
ctx.replyToMessage
) {
for (let v of adminAction) {
if (ctx.text?.startsWith(v.text)) {
v.callBack(ctx);
}
}
} else if (
teamAction.find((x) => ctx.text?.startsWith(x.text)) &&
team.find((x) => x.id == ctx.from.id)
) {
for (let v of teamAction) {
if (ctx.text?.startsWith(v.text)) {
v.callBack(ctx);
}
}
}
});
setInterval(() => {
const day = new Date().getDay();
if (day == 4 || day == 5) {
return;
}
notif();
}, 10800000);
setInterval(() => {
for (let v of team) {
if(v.free > 0){
v.free--;
}
}
// fs.writeFileSync("./data/Admin.json", JSON.stringify(admins));
// fs.writeFileSync("./data/Team.json", JSON.stringify(team));
// fs.writeFileSync("./data/Data.json", JSON.stringify(data));
bot.telegram.sendDocument(admins[0],Buffer.from(JSON.stringify(admins)),{filename : "admin.json"})
bot.telegram.sendDocument(admins[0],Buffer.from(JSON.stringify(team)),{filename : "team.json"})
bot.telegram.sendDocument(admins[0],Buffer.from(JSON.stringify(data)),{filename : "data.json"})
}, 1000 * 60 * 60 * 24);
bot.run();