-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bot.cs
476 lines (445 loc) · 15 KB
/
Bot.cs
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
using System.Collections.Generic;
using System.Linq;
using Calendar.Analyzer;
using Calendar.Command;
using Calendar.ItemCalendar;
using Calendar.ItemCategory;
using Calendar.ItemOrganizer;
using Calendar.ItemSettings;
using Calendar.OrganizerTelegram;
using Calendar.Settings;
using Telegram.Bot;
using Telegram.Bot.Types;
namespace Calendar
{
class BotEssence
{
protected System.String ApiKey { get; set; }
protected TelegramBotClient BotClient { get; set; }
protected DataBaseContext baseContext { get; set; } = new DataBaseContext();
protected List<ICommand> commands = new List<ICommand>();
protected List<ICommandSettings> commandSettings = new List<ICommandSettings>();
protected List<IOrganizer> commandiOrganizer = new List<IOrganizer>();
protected Dictionary<System.Int32, IItemCategory> pairs = new Dictionary<System.Int32, IItemCategory>();
protected Dictionary<System.Int32, IEventCal> eventCals = new Dictionary<System.Int32, IEventCal>();
protected Dictionary<System.Int32, Calendar> keyValues = new Dictionary<System.Int32, Calendar>();
protected Dictionary<System.Int32, IEvetnEach> eventEach = new Dictionary<System.Int32, IEvetnEach>();
protected Dictionary<System.Int32, ISettings> iSettings = new Dictionary<System.Int32, ISettings>();
protected Dictionary<System.Int32, IItemOrganizer> iOrganizer = new Dictionary<System.Int32, IItemOrganizer>();
public BotEssence(System.String Api)
{
ApiKey = Api;
BotClient = new TelegramBotClient(ApiKey);
SetCalendar();
SetCommands();
SetCommandSettings();
SetIsettings();
SetCommandiOrganizer();
setIOrganizer();
SetEventCals();
SetEventEach();
SetCategory();
}
private void SetCalendar()
{
}
private void SetCommands()
{
commands = new List<ICommand>() //--- Список команд
{
new StartMenu(),
new Category(),
new News(),
new Sport(),
new Notes(),
new Cooking(),
new Documents(),
new Video(),
new Entertainment(),
new Finance(),
new Travels(),
new Cars(),
new Buy(),
new Anather(),
new BackToCategory(),
new NewsShow(),
new AddItemCategory(),
new DeleteNotes(),
new ChangeFirst(),
new ChangeSecond(),
new BackToNews(),
new StartSettingsOne(),
new StartOrganizer()
};
}
private void SetCommandSettings()
{
commandSettings = new List<ICommandSettings>()
{
new AddE_Mail(),
new BackToSettingsOne(),
new BackToSettingsTwo(),
new BackToSettingsThree(),
new BackToSettingsFour(),
new DeleteE_Mail(),
new YesDeleteE_Mail(),
new NoDeleteE_Mail(),
new SubscribeToTheNewsletterE_Mail(),
new SubscribeToTheNewsletterTelegram()
};
}
private void SetIsettings()
{
iSettings = new Dictionary<System.Int32, ISettings>()
{
{ 37, new E_mail() }
};
}
private void SetCommandiOrganizer()
{
commandiOrganizer = new List<IOrganizer>()
{
new BackToOrganizer(),
new OrganizerTimeToWork(),
new OrganizerTimeToRelaxation(),
new OrganizerSattisticMouth(),
new StartOrganizerTime(),
new StartOrganizerTimeRelax()
};
}
private void setIOrganizer()
{
iOrganizer = new Dictionary<System.Int32, IItemOrganizer>()
{
{ 38, new Organizer() }
};
}
private void SetEventCals()
{
eventCals = new Dictionary<System.Int32, IEventCal>()
{
{ 26, new ReminderCal() }, //--- Напоминание
{ 27, new PurposeCal() }, //--- Цель
{ 28, new EventCal() }
};
}
private void SetEventEach()
{
eventEach = new Dictionary<System.Int32, IEvetnEach>()
{
{ 31, new AddEachDay() }
};
}
private void SetCategory()
{
pairs = new Dictionary<System.Int32, IItemCategory>()
{
{ 0, new NothingCat() },
{ 11, new NewsCat() },
{ 12, new SportCat() },
{ 13, new NotesCat() },
{ 14, new CookingCat() },
{ 15, new DocumentsCat() },
{ 16, new VideoCat() },
{ 17, new EntertainmentCat() },
{ 18, new FinanceCat() },
{ 19, new TravelsCat() },
{ 20, new CarsCat() },
{ 21, new BuyCat() },
{ 22, new AnatherCat() }
};
}
}
class Bot : BotEssence
{
public readonly List<ICalendar> calendars = new List<ICalendar>();
public Bot(System.String api) : base(api)
{
System.Console.WriteLine(BotClient.GetMeAsync().Result);
calendars = new List<ICalendar>()
{
#region 1
new CalendarBot(),
new Next(),
new Back(),
new BackToStart(),
new BackToCalendar(),
new AddReminder(),
new ShowOneDayCalendar(),
new AddContextReminder(),
new AddContextPurpose(),
new AddContextEvent(),
new BackToMenuReminder(),
new AddTime(),
new AddReminderReiteration(),
new EachDayReminder(),
new EachWeakReminder(),
new EachMouthReminder(),
new EachYearReminder(),
new EachDayPurpose(),
new EachWeakPurpose(),
new EachMouthPurpose(),
new EachYearPurpose(),
new EachDayEvent(),
new EachWeakEvent(),
new EachMouthEvent(),
new EachYearEvent(),
new BackToevent(),
new AddPurpose(),
new AddPurooseReiteration(),
new AddEventReiteration(),
new DurationPurpose(),
new BackToPurpose(),
new BackToReminder(),
new DurationPurposeTime15(),
new DurationPurposeTime30(),
new DurationPurposeTime1(),
new DurationPurposeTime2(),
new AddEventNotBusy(),
new AddEventBusy(),
new AddEventNotBusy2(),
new AddLocation(),
new ShowEvent(),
new ShowReminder(),
new ShowPurpose(),
new BackToChoseDate(),
new ChangeReminderName(),
new ChangeReminderNote(),
new ChangeReminderReiteration(),
new DeleteAllEvent(),
new ChangeAllTime(),
#endregion
new ChangePurposeName(),
new ChangePurposeNote(),
new ChangePurposeReiteration(),
new ChangeEventLocation(),
new ChangeEventReiteration(),
new BackToChangePurpose(),
new BackToChangeReminder(),
new BackToChangeEvent(),
new OrganizerSattisticDay(),
new ChangeEventName(),
new ChangeEventNote()
};
BotClient.OnMessage += BotAnaliz;
BotClient.OnCallbackQuery += CallBack;
BotClient.StartReceiving();
}
private void CallBack(System.Object sender, Telegram.Bot.Args.CallbackQueryEventArgs e)
{
if(commands.Any(c => c.Equals(e.CallbackQuery.Data))) // проверка есть ли команда в списке
{
ICommand Command = commands.FirstOrDefault(c => c.Equals(e.CallbackQuery.Data)); // вытягиваем класс
Command.Execute(BotClient, e.CallbackQuery, pairs, baseContext);
}
else if(calendars.Any(c => c.Equals(e.CallbackQuery.Data)))
{
if(!keyValues.Any(c => c.Key == e.CallbackQuery.From.Id) || keyValues.Count == 0)
{
keyValues.Add(e.CallbackQuery.From.Id, new Calendar());
}
ICalendar Command = calendars.FirstOrDefault(c => c.Equals(e.CallbackQuery.Data)); // вытягиваем класс
if(Command.Name == "BackToStart" || Command.Name == "BackToCalendar"
|| Command.Name == "Calendar" || Command.Name == "<"
|| Command.Name == ">")
{
Command.Execute(BotClient, e.CallbackQuery, keyValues, baseContext);
}
else
{
Command.Execute(BotClient, e.CallbackQuery, eventCals, baseContext);
}
}
else if(commandSettings.Any(c => c.Equals(e.CallbackQuery.Data)))
{
ICommandSettings ISettings = commandSettings.FirstOrDefault(c => c.Equals(e.CallbackQuery.Data));
ISettings.Execute(BotClient, e.CallbackQuery, iSettings, baseContext);
}
else if(commandiOrganizer.Any(c => c.Equals(e.CallbackQuery.Data)))
{
IOrganizer iTOrganizer = commandiOrganizer.FirstOrDefault(c => c.Equals(e.CallbackQuery.Data));
iTOrganizer.Execute(BotClient, e.CallbackQuery, iOrganizer, baseContext);
}
else
{
User users = baseContext._User.Where(p => p.ID == e.CallbackQuery.From.Id).FirstOrDefault();
if(users.Work / 100 <= 22)
{
ChouseItem chouseItem = new ChouseItem();
chouseItem.Execute(BotClient, e.CallbackQuery, pairs, baseContext);
}
else if(users.Work / 100 == 30)
{
ChouseData chouseData = new ChouseData();
chouseData.Execute(BotClient, e.CallbackQuery, baseContext);
}
else if(users.Work % 100 >= 26 && users.Work % 100 <= 28)
{
ShowItemCalndar showItemCalnder = new ShowItemCalndar();
showItemCalnder.Execute(BotClient, e.CallbackQuery, eventCals, baseContext);
}
}
}
private void BotAnaliz(System.Object sender, Telegram.Bot.Args.MessageEventArgs e)
{
if(e.Message.Text != null)
{
if(!e.Message.Text.Equals("/start"))
{
Analize t = new Analize();
User users = baseContext._User.Where(p => p.ID == e.Message.From.Id).FirstOrDefault();
if((users.Work / 100) < 26)
{
t.StartAnalize(BotClient, e.Message, pairs, baseContext);
}
else if((users.Work / 100) >= 26 && (users.Work / 100) < 31 || (users.Work / 100) == 33
|| (users.Work / 100) == 34 || (users.Work / 100) == 35 || (users.Work / 100) == 36
|| (users.Work / 100) == 32)
{
t.StartAnalize(BotClient, e.Message, eventCals, baseContext);
}
else if((users.Work / 100) == 31)
{
t.StartAnalize(BotClient, e.Message, eventEach, baseContext);
}
else if((users.Work / 100) == 37)
{
t.StartAnalize(BotClient, e.Message, iSettings, baseContext);
}
else if((users.Work / 100) == 38 || (users.Work / 100) == 39)
{
t.StartAnalize(BotClient, e.Message, iOrganizer, baseContext);
}
}
}
if(commands.Any(c => c.Equals(e.Message.Text))) // проверка есть ли команда в списке
{
try
{
commands.FirstOrDefault(c => c.Equals(e.Message.Text)).Execute(BotClient, e.Message, pairs, baseContext); // вытягиваем класс
}
catch(System.Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
else if(calendars.Any(c => c.Equals(e.Message.Text)))
{
try
{
if(!keyValues.Any(c => c.Key == e.Message.From.Id) || keyValues.Count == 0)
{
keyValues.Add(e.Message.From.Id, new Calendar());
}
calendars.FirstOrDefault(c => c.Equals(e.Message.Text)).Execute(BotClient, e.Message, keyValues, baseContext); // вытягиваем класс
}
catch(System.Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
}
}
class Analize
{
private readonly List<List<System.Int32>> Vs = new List<List<System.Int32>>();
private readonly Dictionary<List<System.Int32>, IAnalize> AbstractAnaliz = new Dictionary<List<System.Int32>, IAnalize>();
public Analize()
{
Vs = new List<List<System.Int32>>
{
new List<System.Int32> { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, /*-Для Категории-*/ 26, 27, 28/*-Для календаря-*/ }, //--- Определение категории
new List<System.Int32> { 23, /*-Для Категории-*/ 29 /*-Для календаря-*/ }, //--- Определение описания
new List<System.Int32> { 24 }, //--- Определение изменения названия
new List<System.Int32> { 25 }, //--- Определение изменения описания
new List<System.Int32> { 30 }, //--- Добавление даты
new List<System.Int32> { 31 }, //--- Анализ повторение которое будет(Один день, каждый день, каждую неделю, каждый месяц, каждый год)
new List<System.Int32> { 32 }, //--- Добавление локации.
new List<System.Int32> { 33 }, //--- Изменение название в календаре
new List<System.Int32> { 34 }, //--- Изменение описание в календаре
new List<System.Int32> { 35 }, //--- Изменение времени в календаре
new List<System.Int32> { 36 },
new List<System.Int32> { 37 }, //--- Добавление E-Mail
new List<System.Int32> { 38, 39 } //--- Добавление TimeToWork and TimeToRelaxation
};
AbstractAnaliz = new Dictionary<List<System.Int32>, IAnalize>()
{
{ Vs[0], new AnalizeName() },
{ Vs[1], new AnalizeContext() },
{ Vs[2], new AnalizeChangeFirst() },
{ Vs[3], new AnalizeChangeSecond() },
{ Vs[4], new AnalizeTime() },
{ Vs[5], new AnalizeEach() },
{ Vs[6], new AnalizeLocation() },
{ Vs[7], new AnalizeChangeFirst() },
{ Vs[8], new AnalizeChangeSecond() },
{ Vs[9], new AnalizChangeTime() },
{ Vs[10], new AnalizChangeLocation()},
{ Vs[11], new AnalizeE_Mail() },
{ Vs[12], new AnalizeTimeOrganizer()}
};
}
public void StartAnalize(TelegramBotClient BotClient, Message _message, System.Object itemCategories, DataBaseContext baseContext)
{
InlineButton inlineButton = new InlineButton();
InlineButtonCalendar inlineButtonCalendar = new InlineButtonCalendar();
InlineButtonSettings inlineButtonSettings = new InlineButtonSettings();
InlineButtonOrganizer inlineButtonOrganizer = new InlineButtonOrganizer();
User users = baseContext._User.Where(p => p.ID == _message.From.Id).FirstOrDefault();
System.Console.WriteLine(_message.From.Id);
System.Console.WriteLine(users.Work / 100 + " " + users.Work);
if((users.Work / 100) < 29 && (users.Work % 100) != 0)
{
foreach(KeyValuePair<List<System.Int32>, IAnalize> pair in AbstractAnaliz)
{
if(pair.Key.Contains(users.Work / 100) && (users.Work / 100) < 26)
{
IAnalize temp = AbstractAnaliz[pair.Key] as IAnalize;
temp.SetName(BotClient, _message, users, inlineButton, itemCategories, baseContext);
return;
}
else if(pair.Key.Contains(users.Work / 100) && ((users.Work / 100) > 26 || (users.Work / 100) < 29))
{
IAnalize temp = AbstractAnaliz[pair.Key] as IAnalize;
temp.SetName(BotClient, _message, users, inlineButtonCalendar, itemCategories, baseContext);
return;
}
}
}
else if((users.Work / 100) >= 29 && (users.Work / 100) < 37 && (users.Work % 100) != 0)
{
foreach(KeyValuePair<List<System.Int32>, IAnalize> pair in AbstractAnaliz)
{
if(pair.Key.Contains(users.Work / 100))
{
IAnalize temp = AbstractAnaliz[pair.Key] as IAnalize;
temp.SetName(BotClient, _message, users, inlineButtonCalendar, itemCategories, baseContext);
return;
}
}
}
else if((users.Work / 100) == 37)
{
foreach(KeyValuePair<List<System.Int32>, IAnalize> pair in AbstractAnaliz)
{
if(pair.Key.Contains(users.Work / 100))
{
IAnalize temp = AbstractAnaliz[pair.Key] as IAnalize;
temp.SetName(BotClient, _message, users, inlineButtonSettings, itemCategories, baseContext);
}
}
}
else if((users.Work / 100) == 38 || (users.Work / 100) == 39)
{
foreach(KeyValuePair<List<System.Int32>, IAnalize> pair in AbstractAnaliz)
{
if(pair.Key.Contains(users.Work / 100))
{
IAnalize temp = AbstractAnaliz[pair.Key] as IAnalize;
temp.SetName(BotClient, _message, users, inlineButtonOrganizer, itemCategories, baseContext);
}
}
}
}
}
}