69 |
70 | How was the idea for this project born?
71 |
72 | I was baffled when I tried the libraries to interact with the telegram bot api, because I had never written such bad code before.
73 | All those endless configurations of objects through setters, changeable object state, class names that don't fit in one screen, side effects that come out of thin air.
74 | Libraries force us to write this garbage. After prolonged use of these libraries I got sick of it and so the idea of creating elegram-api was born.
75 |
76 |
77 |
78 | Here some problems that I found in other projects:
79 |
88 |
89 |
90 | Let's see how bad code produces good solutions.
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/src/main/java/ru/elegramapi/www/bot/BtDefault.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2022-2023 Ivanchuck Ivan.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included
14 | * in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | /*
25 | * @todo #60 Design/ Testing.
26 | * Write tests for DefaultBot class after closing other issues in DefaultBot class.
27 | * */
28 | /*
29 | * @todo #106 Fix #handleUpdates.
30 | * This method work unpredictable,
31 | * need to fix work with incoming updates.
32 | * */
33 | package ru.elegramapi.www.bot;
34 |
35 | import com.jcabi.http.response.JsonResponse;
36 | import java.io.IOException;
37 | import java.util.HashSet;
38 | import java.util.List;
39 | import java.util.Set;
40 | import java.util.concurrent.BlockingQueue;
41 | import java.util.concurrent.LinkedBlockingQueue;
42 | import java.util.concurrent.atomic.AtomicInteger;
43 | import org.cactoos.list.ListOf;
44 | import org.json.JSONArray;
45 | import org.json.JSONObject;
46 | import ru.elegramapi.www.Bot;
47 | import ru.elegramapi.www.Command;
48 | import ru.elegramapi.www.request.TRqGetUpdates;
49 | import ru.elegramapi.www.request.TRqPost;
50 | import ru.elegramapi.www.request.TRqSendMessage;
51 | import ru.elegramapi.www.request.TRqWithChatId;
52 | import ru.elegramapi.www.request.TRqWithOffset;
53 | import ru.elegramapi.www.request.TRqWithText;
54 | import ru.elegramapi.www.update.UpdDefault;
55 |
56 | /**
57 | * The default implementation of {@link Bot}.
58 | *
59 | * @since 0.0.0
60 | */
61 | public class BtDefault implements Bot {
62 |
63 | /**
64 | * All commands.
65 | */
66 | private final List