Skip to content
This repository was archived by the owner on May 17, 2022. It is now read-only.

Commit b370df9

Browse files
committed
Merge branch 'main' into release
2 parents 80caa45 + 09e23fe commit b370df9

File tree

5 files changed

+141
-22
lines changed

5 files changed

+141
-22
lines changed

.travis.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

Docs/build failing.svg

Lines changed: 1 addition & 0 deletions
Loading

Docs/build passing.svg

Lines changed: 1 addition & 0 deletions
Loading

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<p align="center">
2+
<img src="Docs/logo.png">
3+
<h1 align="center">Telegram RSS Bot</h1>
4+
<p align="center">
5+
<a href="http://de1.hashbang.sh:7191">
6+
<img alt="" src="http://de1.hashbang.sh:7191/build_state">
7+
</a>
8+
<a href="https://github.com/bsimjoo/Telegram-RSS-Bot/labels/bug">
9+
<img alt="Bug issue" src="https://img.shields.io/github/issues-raw/bsimjoo/Telegram-RSS-Bot/bug?color=red">
10+
</a>
11+
<a href="http://de1.hashbang.sh:7191">
12+
<img alt="Reported bugs from pcworms_bot project" src="https://img.shields.io/badge/dynamic/json?url=http://de1.hashbang.sh:7191/json&label=Bugs+found&query=$.Telegram_RSS_Bot.bugs_count&color=red">
13+
</a>
14+
<a href="https://github.com/bsimjoo/Telegram-RSS-Bot/labels/todo">
15+
<img src="https://img.shields.io/github/issues-raw/bsimjoo/Telegram-RSS-Bot/todo?color=orange&label=TODOs">
16+
</a>
17+
<a href="https://github.com/bsimjoo/Telegram-RSS-Bot/releases">
18+
<img src="https://img.shields.io/github/v/release/bsimjoo/Telegram-RSS-Bot">
19+
</a>
20+
<a href="LICENSE.md">
21+
<img src="https://img.shields.io/github/license/bsimjoo/Telegram-RSS-Bot">
22+
</a>
23+
<img src="https://img.shields.io/badge/Python-v3.8-blue">
24+
<a href="https://core.telegram.org/bots/api-changelog">
25+
<img src="https://img.shields.io/badge/Bot%20API-5.1-blue?logo=telegram">
26+
</a>
27+
</p>
28+
<p align="center">
29+
A simple telegram bot that started for <a href="http://pcworms.blog.ir">pcworms.blog.ir</a> weblog that read RSS Feeds and send newest feed to all chats(in this article chats = [all PVs, all GPs and all channels]).
30+
Administrators can also send photos, markdown or simple text messages to chats.</p>
31+
</p>
32+
33+
## Owner
34+
The person who runs bot-server and has telegram-bot token. He usually has access to source code and Databases.
35+
36+
*Owner can change source of feeds but default source is `http://pcworms.blog.ir/rss` read [Installation](#installation)*
37+
38+
### How the owner is identified
39+
Owner (bot call him as lord!) can identify himself using the token he got from @botfather like this: `/start {bot-token}`
40+
41+
### Owner can:
42+
- Generate one-time tokens and add admins. (No remove option at now)
43+
- Get muted notification of bot join/kick from a GP or channel.
44+
- Get notification of Errors and Exceptions (usefull for report to me).
45+
- What Others (Admins and users) can do.
46+
47+
## Admin
48+
A user can promote as admin just if Owner give him a one-time token who got from bot;
49+
then user can use one-time token for promotion like this:
50+
```
51+
/start {token}
52+
```
53+
Then Owner Receive a message with admin information and accept/decline button.
54+
55+
### Admins can:
56+
- Send photo, markdown or simple text messages to all chats
57+
- Send last feed to all chats
58+
- Get bot statistics (chats, members and admins count)
59+
- Get a list of all chats with username, fullname and ... (except profile photo and phone number)
60+
- Change the interval between each check for a new post
61+
62+
### Users can:
63+
- Get last feed
64+
- *No more option*
65+
66+
---
67+
`/help` command will give you a list of all available command related to user level.
68+
69+
# Languages
70+
Available languages:
71+
- en-US
72+
- fa-IR
73+
- [*+Add more+*](https://github.com/bsimjoo/Telegram_RSS_bot/edit/main/default-strings.json)
74+
You can translate [default-strings.json](default-strings.json) file to add more languages but this bot will use same language for all users, I will make it multilingual for users in future. Owner and admin interface is hardcoded in english (except `/help` command) and [strings.json](strings.json) use to comunicating with users.
75+
76+
**Notice** Rename you custom strings file to `strings.json` to prevent git pull errors. (`strings.json` is ignored for your custom version)
77+
78+
# Installation:
79+
First of all admin need to create a new bot using telegram @BotFather and keep Bot-Token safe. then Download Comprressed Source or use git clone
80+
```bash
81+
git clone https://github.com/bsimjoo/Telegram_RSS_bot.git
82+
```
83+
84+
Change working directory to source directory and install requirements using this commands:
85+
```
86+
cd ./Telegram_RSS_Bot
87+
python3 -m pip install --user -r requirements.txt
88+
```
89+
wait until installation finish without any error. (You can report errors to me)
90+
91+
Then configure and run the server for first use.
92+
```
93+
python3 main.py -t {bot-token-here} -s {source-here} -l {language}
94+
```
95+
The program will save the configurations for reuse in the database, so you do not need to reconfigure the server for the next run, unless you need to change them.
96+
97+
Identify yourself as owner to bot. you can start a chat with your bot and then use this:
98+
```
99+
/start {bot-token}
100+
```
101+
102+
# Reset databases
103+
If your about to reset database you can use `-r {database}` to reset `chats`, `config` or `all` databases.
104+
105+
**:warning: This action can not be undone**
106+
107+
# Bug Reporter
108+
I added a module that reports exceptions or any custom message and counts them, then I can show the number of bugs through a running server and then track and fix them. The bug reporter is not enabled by default, but if you are interested you can save the bugs to a local file `bug.json` by running the server with the `-b` argument, or run the bug report http server with `-b {port number}` to see them through an http server (click on the "Bugs found" badge to see an example).
109+
110+
**Notice** Don't forget to install `cherrypy` for online bug reporter using `python3 -m pip install cherrypy`
111+
112+
---
113+
Using [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot) api
114+
115+
###### this is my first telegram bot!
116+
this project began for [pcworms.blog.ir](http://pcworms.blog.ir) weblog, but now it is available for everyone. you can see customised version at [pcworms/PCworms_Bot](https://github.com/pcworms/PCworms_Bot)

main.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,39 +1076,49 @@ def idle(self):
10761076

10771077
if port:
10781078
import cherrypy #user can ignore installing this mudole if now need for http reporting
1079-
conf = {'global':
1080-
{
1081-
"server.socket_host": '0.0.0.0',
1082-
"server.socket_port": port
1083-
},
1084-
'log.screen': False
1085-
}
1086-
import cherrypy
10871079
class root:
1088-
def __init__(self, reporter):
1080+
def __init__(self, reporter, bug_reporter):
10891081
self.reporter = reporter
1082+
self.bug_reporter = bug_reporter
10901083

10911084
@cherrypy.expose
10921085
def index(self):
10931086
res = '''<html style="weidth:100%"><body><h1>Bugs</h1><hr>
10941087
<b>what is this page?</b> this project is using a simple
10951088
web server to report bugs(exceptions) that found in a running program.
1096-
<h2>Bug logs</h2><pre language="json" style="weidth:100%;overflow:auto">'''+html.escape(self.reporter.dumps())+'</pre></body></html>'
1089+
<h2>Bug logs</h2><pre language="json" style="weidth:100%;overflow:auto">'''+html.escape(self.bug_reporter.dumps())+'</pre></body></html>'
10971090
return res
10981091

1092+
@cherrypy.expose
1093+
def build_state(self):
1094+
cherrypy.response.headers['Content-Type'] = "image/svg+xml;charset=utf-8"
1095+
if self.reporter.data['bugs_count']>0:
1096+
return open('Docs/build faling.svg', 'rb')
1097+
else:
1098+
return open('Docs/build passing.svg', 'rb')
1099+
10991100
@cherrypy.expose
11001101
@cherrypy.tools.json_out()
11011102
def json(self):
1102-
return self.reporter.reports
1103+
return self.bug_reporter.reports
11031104

1105+
1106+
cherrypy.log.access_log.propagate = False
1107+
cherrypy.tree.mount(root(reporter, bug_reporter),'/')
1108+
conf = {'global':
1109+
{
1110+
"server.socket_host": '0.0.0.0',
1111+
"server.socket_port": port,
1112+
'log.screen': False
1113+
}
1114+
}
11041115
cherrypy.config.update(conf)
1105-
cherrypy.tree.mount(root(bug_reporter),'/')
11061116
cherrypy.engine.start()
11071117
web_reporter = True
11081118

11091119
logger.info(f'reporting bugs at {port} and saving them in bugs.json')
11101120
else:
1111-
logger.info(f'saving bugs in {path}')
1121+
logger.info(f'saving bugs in bugs.json')
11121122

11131123
with env.begin(config_db, write = True) as txn:
11141124
if '-t' in argv and len(argv) > 1:

0 commit comments

Comments
 (0)