Skip to content

Commit d954888

Browse files
Merge pull request #128 from MasterCruelty/develop
🚀 Update documentation
2 parents 1e5955c + 0ce84ad commit d954888

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

doc/documentation.pdf

45.6 KB
Binary file not shown.

doc/documentation.tex

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@
1919
%-------------------------------------------------------
2020

2121
\begin{center} In this file I resume how Robbot works with more details than the README file you can find in the repository.
22-
Robbot is a Telegram bot with a bunch of different features. Some of them extend the use of Telegram you usually do, some of them are just funny features.\\
23-
The bot is written in Python and it is running in Python3.8 at the moment.\end{center}
22+
\textbf{Robbot} is a Telegram bot with a bunch of different features. Some of them extend the use of Telegram you usually do, some of them are just funny features I liked to develop.\\
23+
The bot is written in Python and it is running in Python3.9 version at the moment.\end{center}
2424

2525
%-------------------------------------------------------
2626
%First section about configuration file
2727
%-------------------------------------------------------
2828
\section{Configuration file}
2929

30-
The configuration file is the first thing you must check because without it well compiled, the bot won't run at all. This file is also well explained in README file so I won't spend a lot of words on it.
30+
The configuration file is the first thing you must check because without it, the bot won't run at all. This file is also well explained in README file in this repository so I won't spend a lot of words on it. \\Essentially you put your keys, additional data and commands' name in the right fields to make the bot work.
3131
\begin{center} $config-example.json \Rightarrow config.json$ \end{center}
3232

3333
\subsection{DB path}
3434
The .db file will be saved in the directory you choose and set in config.json file
3535
\begin{center} $"path-db" \Rightarrow config.json$ \end{center}
3636

3737
\subsection{Super admin data}
38-
In this section we put our Telegram data as super admin(the only one) of the bot. The super admin is able to manage the db changes such as adding users, promote to admin and deleting users/revoke admin powers.
38+
In this section we put our Telegram data as super admin(the only one) of the bot. The super admin is able to manage the db changes such as adding users, promote to admin and deleting users/revoke admin powers.\\
39+
This type of user can also modify the value of a few data like the number of uses of commands for a specific user or managing the amount of uses for openai commands of premium users.
3940
\begin{center} $"id-super-admin" \Rightarrow config.json$ \end{center}
4041

4142
\subsection{commands,admin commands and super}
@@ -49,9 +50,9 @@ \subsection{commands,admin commands and super}
4950
%Second section about app.py(main)
5051
%-------------------------------------------------------
5152
\section{Main}
52-
app.py is the main source file. It creates the session, it connects with Telegram API using Pyrogram Client class and it's in constant wait for arriving messages.
53-
First of all it fetches the information from configuration file, then it starts the connection.
54-
While waiting, the bot will ignore any messages it doesn't recognize as a known command. Otherwise if it's a known command, it checks for permission to the user launched that command. If it's a recognized user, the entire message will be managed by a parser function and passed to a specific fetch function written inside controller.py.
53+
\textbf{app.py} is the main source file. It creates the session, it connects with Telegram API using Pyrogram Client class and it's in constant wait for arriving messages.\\
54+
First of all it fetches the information from configuration file, then it starts the connection.\\
55+
While waiting, the bot will ignore any messages it doesn't recognize as a known command. Otherwise if it's a known command, it checks for permission to the user launched that command. If it's a recognized user, the entire message will be managed by a parser function and moved to a specific fetch function written inside \textbf{controller.py}.\\
5556
If a command isn't launched by a registered user, the bot will reply with a default message.
5657
\begin{center} $app.py \xrightarrow{\text{command}} controller.py$ \end{center}
5758

@@ -60,21 +61,21 @@ \section{Main}
6061
%-------------------------------------------------------
6162
\section{Controller}
6263
Just like in the MVC design pattern, this controller takes the input arriving from the main and it calls the right function in the right source file in $utils$ and $modules$ folders. How it works? \\
63-
There are three dictionaries dedicated to the three types of command(user,admin,super). The key is the command and the value is the path of function it executes. As said in Main section, here we have the fetch command functions matched with the dictionaries mentioned in the previous row. The specific function will return a sendMessage and then the main will wait for the next command.
64+
There are three dictionaries dedicated to the three types of commands which are as said in before \textbf{(user,admin,super)}. \\The key is the command and the value is the path of function it executes. \\As said in Main section, here we have the fetch command functions matched with the dictionaries mentioned in the previous row. The specific function will return a \textbf{sendMessage} or a \textbf{sendMedia} function and then the main will wait for the next command.
6465
\begin{center} $controller.py \xrightarrow{\text{command fetched}} (modules \ or \ utils)$ \end{center}
6566

6667
\subsection{parser function}
67-
This simple function mentioned in the first section takes the input message as argument and it deletes the command at the beginning, returning then just the query that will be sended by the controller to the right module which will manage and execute it.
68+
This simple function mentioned in the previous sections takes the input message as argument and it deletes the command at the beginning, returning then just the text "query" that will be sended by the controller to the right module which will manage and execute it.
6869

6970
\subsection{other details}
70-
Inside the controller there is also a small function(visualizza) which print the current state of the incoming message on terminal such as a live log. \\
71+
Inside the controller there is also a small function called \textbf{visualizza} which print the current state of the incoming message on terminal such as a live log.\\ During the execution of this function, the log is also sended as a Telegram message to the super admin private chat, including possible errors/exceptions. \\
7172

7273
%-------------------------------------------------------
7374
%4th section about the get_config source file
7475
%-------------------------------------------------------
7576
\section{get-config}
7677
this source file contains some support functions that are often used in many situations. The first one return in a variable the content of the configuration file to get the fields easily. \\
77-
The remaining functions are all about Telegram features such as getting information from the json message or renaming for example the send-message of Pyrogram to avoid including the decorator in every source file and just call this one by including get-config.
78+
The remaining functions are all about Telegram features such as getting information from the json message or renaming for example the \textit{send-message} of \textbf{Pyrogram} to avoid including the decorator in every source file and just call this one by including get-config.
7879
\begin{center} $app.py \xrightarrow{\text{get-config-file()}} running$ \end{center}
7980

8081
%-------------------------------------------------------
@@ -84,23 +85,27 @@ \section{sysfunctions}
8485
This file contains functions using directly Telegram features such as the poll function or get-message. It also includes the help function.
8586

8687
\section{Summary till now}
87-
\begin{center} $app.py \xrightarrow{\text{get-config-file()}} running$ \end{center}
88-
\begin{center} $app.py \xrightarrow{\text{command}} controller.py$ \end{center}
89-
\begin{center} $controller.py \xrightarrow{\text{command fetched}} (modules \ or \ utils)$ \end{center}
90-
\begin{center} $(modules \ or \ utils) \xrightarrow{\text{return message}} app.py$ \end{center}
91-
\begin{center} $app.py \xrightarrow{\text{waiting for the next command}} app.py$ \end{center}
88+
\begin{center} $app.py \xrightarrow{\text{\textbf{get-config-file()}}} running$ \end{center}
89+
\begin{center} $app.py \xrightarrow{\text{\textbf{command}}} controller.py$ \end{center}
90+
\begin{center} $controller.py \xrightarrow{\text{\textbf{command fetched}}} (modules \ or \ utils)$ \end{center}
91+
\begin{center} $(modules \ or \ utils) \xrightarrow{\text{\textbf{return message or media}}} app.py$ \end{center}
92+
\begin{center} $app.py \xrightarrow{\text{\textbf{waiting for the next command}}} app.py$ \end{center}
9293

9394
%-------------------------------------------------------
9495
%6th section about database
9596
%-------------------------------------------------------
9697
\section{Database}
97-
In this section we'll focus about the database structure. There are two main table: User and Stats. \\
98-
the first one saves data of users such as Telegram id(to check if it's registered) and a couple of boolean fields for admin rights.\\
99-
The Stats table is linked to the User one by the id field and it saves information about how many times a command is used by every users.
100-
There's also a Group table but it's not used at the moment, maybe in the future or not at all and it will be deleted in that case.\\
101-
98+
In this section we'll focus about the database structure. There are several tables linked each other: \textbf{User, Stats, Trivial, Group, OpenAICredit}. \\ \\ \\
99+
The \textbf{User} table saves data of users(Telegram id, first name and username(if it exists otherwise None value), there are also a couple of boolean field to set admin or superadmin rights.\\ \\
100+
The \textbf{Stats} table is linked to the User one by the id field and it saves information about how many times a command is used by every user. \\ \\
101+
The \textbf{Group} table saves chat-id, chat-name and a third string field. This table is used to save a specific command to execute only in specific group chats.\\ \\
102+
The \textbf{Trivial} table is used to manage the score points of the Trivial game developed inside this bot. It's linked to the User table by the id as foreign key. \\ \\
103+
The \textbf{OpenAICredit} table is linked to the User table by the id as foreign key, just used to manage number of uses of premium commands for premium users.
104+
105+
%---Inizializzazione della figura tikz
102106
\begin{tikzpicture}[relation/.style={rectangle split, rectangle split parts=#1, rectangle split part align=base, draw, anchor= center, align=center, text height=3mm, text centered}]\hspace*{-0.3cm}
103107

108+
%--figura relativa alla tabella User
104109
\node (usertitle) {\textbf{User}};
105110
\node [relation=5, rectangle split horizontal, rectangle split part fill={lightgray!50}, anchor= north west, below=0.6cm of usertitle.west,anchor=west] (user)
106111
{\underline{id\_user}
@@ -109,15 +114,36 @@ \section{Database}
109114
\nodepart{four} admin
110115
\nodepart{five} superadmin};
111116

117+
%--figura relativa alla tabella Stats
112118
\node [below=1.3cm of user.west,anchor=west] (statstitle) {\textbf{Stats}};
113119
\node [relation=3,rectangle split horizontal, rectangle split part fill ={lightgray!50}, below=0.6cm of statstitle.west,anchor=west] (stats)
114120
{\nodepart{one} id\_user
115121
\nodepart{two} command
116122
\nodepart{three} times };
117123

118-
\draw[-latex] (stats.one south) -- ++(0,-0.2) -| ($(stats.one south) + (4,0)$) |- ($(user.one south) + (0.25,-0.50)$) -| ($(user.one south) + (0.25,0)$);
124+
\draw[-latex] (stats.one south) -- ++(0,-0.2) -| ($(stats.one south) + (3.75,0)$) |- ($(user.one south) + (0.25,-0.50)$) -| ($(user.one south) + (0.01,0)$);
125+
126+
%--figura relativa alla tabella Trivial
127+
\node [below=1.3cm of stats.west,anchor=west] (trivialtitle) {\textbf{Trivial}};
128+
\node [relation=3,rectangle split horizontal, rectangle split part fill ={lightgray!50}, below=0.6cm of trivialtitle.west,anchor=west] (trivial)
129+
{\nodepart{one} id\_user
130+
\nodepart{two} category
131+
\nodepart{three} points };
132+
133+
\draw[-latex] (trivial.one south) -- ++(0,-0.2) -| ($(trivial.one south) + (3.90,0)$) |- ($(user.one south) + (0.30,-0.400)$) -| ($(user.one south) + (0.15,0)$);
134+
135+
%--figura relativa alla tabella OpenAICredit
136+
\node [below=1.3cm of trivial.west,anchor=west] (openaicredittitle) {\textbf{OpenAICredit}};
137+
\node [relation=2,rectangle split horizontal, rectangle split part fill ={lightgray!50}, below=0.6cm of openaicredittitle.west,anchor=west] (openaicredit)
138+
{\nodepart{one} id\_user
139+
\nodepart{two} amount };
140+
141+
\draw[-latex] (openaicredit.one south) -- ++(0,-0.2) -| ($(openaicredit.one south) + (4,0)$) |- ($(user.one south) + (0.40,-0.300)$) -| ($(user.one south) + (0.25,0)$);
142+
119143

120144
\end{tikzpicture}
121145

146+
\begin{center}
147+
The \textbf{Group} table isn't linked to any table so it isn't shown in this figure. There's also an additional table called \textbf{TrivialSavedData} but it is standalone like the Group one. It is used to save the current active trivial quiz.\end{center}
122148

123149
\end{document}

0 commit comments

Comments
 (0)