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

Commit b0cf4e6

Browse files
authored
Merge pull request #71 from dark0ghost/beta
Beta
2 parents a3eb503 + 20a3633 commit b0cf4e6

14 files changed

+135
-345
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![GitHub issues](https://img.shields.io/github/issues/dark0ghost/async_py_bot)](https://github.com/dark0ghost/async_py_bot/issues)
44
[![GitHub release](https://img.shields.io/github/release/dark0ghost/async_py_bot)](https://github.com/dark0ghost/async_py_bot/releases/)
55
[![Github all releases](https://img.shields.io/github/downloads/dark0ghost/async_py_bot/total.svg)](https://github.com/dark0ghost/async_py_bot/releases/)
6+
[![GitHub code size](https://img.shields.io/github/languages/code-size/dark0ghost/async_py_bot?style=flat)](https://github.com/dark0ghost/async_py_bot)
67

78
# start with docker-compose:
89
```bash

bot.evn

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
TOKEN=""
2+
PAYMENTS_PROVIDER_TOKEN=""
3+
TOKEN_QIWI=""
4+
POSTGRES=""
5+
virustotal=""
6+
etcherscan=""
7+
pastebin=""
8+
cat_api=""
9+
STATS_DB=""
10+
STATS_HOST=""
11+
STATS_USER=""
12+
STATS_PASS=""
13+
MASTER=""

config.json

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
"token": "",
3-
"PAYMENTS_PROVIDER_TOKEN":"",
4-
"TOKEN_QIWI": "",
5-
"POSTGRES": "",
62
"lang":["ru","en"],
73
"mes": {
84
"start": "message start",
@@ -12,7 +8,6 @@
128
"buy": "покупка произведена успешно",
139
"error_pay": "покупка не произошла"
1410
},
15-
"good_proxy_link": "",
1611
"login": {
1712
"login": "",
1813
"password": ""
@@ -61,17 +56,5 @@
6156
"host": "",
6257
"port": 6379
6358
},
64-
"cat_api": {
65-
"token": ""
66-
},
67-
"pastebin": "",
68-
"virustotal": "",
69-
"proxy_use": false,
70-
"wallet": {
71-
"ton": ""
72-
},
73-
"master": "",
74-
"etcherscan":{
75-
"token": ""
76-
}
59+
"master": ""
7760
}

core.py

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
from aiogram.contrib.fsm_storage.redis import RedisStorage2
1010
from aiogram.contrib.middlewares.logging import LoggingMiddleware
1111
from aiogram.utils.callback_data import CallbackData
12-
from aiograph import Telegraph
1312
from aiosocksy.connector import ProxyConnector, ProxyClientRequest
1413

1514
import filter
1615
import helps
17-
from modules import async_proxy, button, keyboard, i18n, ab_api, crypto_price, checker_email, cat_api, io_json_box, \
16+
from modules import button, keyboard, i18n, ab_api, crypto_price, checker_email, cat_api, io_json_box, \
1817
db_pg, etherscan
1918
from modules.com.pastebin import pastebin
2019
from modules.com.virustotal.virustotal import Virustotal
@@ -30,12 +29,11 @@
3029
BASE_DIR: str = (os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + "/bot"
3130

3231
checker_mail: checker_email.CheckerEmail = checker_email.CheckerEmail(hostname_mail=helps.smtp_host,
33-
port=helps.smtp_port, password=helps.smtp_password,
32+
port=helps.smtp_port,
33+
password=helps.smtp_password,
3434
login=helps.smtp_login)
3535
checker_mail.change_len_code(new_len_code=5)
3636

37-
telegraph = Telegraph()
38-
3937
session: aiohttp.ClientSession = aiohttp.ClientSession()
4038

4139
io_json_box: io_json_box = io_json_box.IOJsonBox(session)
@@ -46,11 +44,8 @@
4644

4745
ether_api: etherscan.EtherScan = etherscan.EtherScan(api_key=helps.ether_api, session=session)
4846

49-
5047
debug = True
5148

52-
proxy_use: str = helps.proxy_use
53-
5449
pastebin: pastebin = pastebin.Pastebin(token=helps.pastebian, session=session)
5550

5651
ton = TON(session=session)
@@ -75,17 +70,14 @@
7570

7671
posts_cb: CallbackData = CallbackData('post', 'id', 'action')
7772

78-
Button.posts_cb= posts_cb
73+
Button.posts_cb = posts_cb
7974

80-
Base_filter: filter.Base_bot_filter = filter.Base_bot_filter()
8175
Master_filter: filter.MasterFilter = filter.MasterFilter()
8276

8377
lazy_get_text: i18n.lazy_gettext = i18n.lazy_gettext
8478

8579
lang: List[str] = []
8680

87-
proxy_class = async_proxy.Proxy(session=session)
88-
8981
"""
9082
check debug on debug mode
9183
"""
@@ -96,29 +88,6 @@
9688

9789

9890
# start def
99-
async def setproxy() -> None:
100-
"""
101-
check proxy and add to list
102-
@return:
103-
"""
104-
proxy_box = []
105-
connector = ProxyConnector()
106-
li = await proxy_class.main()
107-
for proxy in li:
108-
try:
109-
async with aiohttp.ClientSession(connector=connector, request_class=ProxyClientRequest) as session:
110-
async with session.get("https://www.telegram.org", proxy=proxy) as response:
111-
log.debug(f"{proxy} valid")
112-
proxy_box.append(proxy)
113-
114-
except Exception as e:
115-
logging.exception(e)
116-
log.info(f"warning {proxy} not valid")
117-
118-
if len(proxy_box) < 2:
119-
log.info(f"log new rec")
120-
await setproxy()
121-
12291

12392
async def task():
12493
"""
@@ -127,17 +96,11 @@ async def task():
12796
@return:
12897
"""
12998
bind = await postgres.connect(url=helps.POSTGRES)
130-
await telegraph.create_account((await bot.get_me())["first_name"])
13199

132100

133101
# end def
134-
if proxy_use:
135-
bot = Bot(token=helps.token, loop=loop,
136-
parse_mode=types.ParseMode.HTML,
137-
proxy=helps.good_proxy_link, proxy_auth=helps.login)
138-
else:
139-
bot = Bot(token=helps.token, loop=loop,
140-
parse_mode=types.ParseMode.HTML)
102+
bot = Bot(token=helps.token, loop=loop,
103+
parse_mode=types.ParseMode.HTML)
141104

142105
dp = Dispatcher(bot, storage=storage)
143106
dp.middleware.setup(LoggingMiddleware())

docker-compose.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ services:
66
context: .
77
dockerfile:
88
Dockerfile
9+
env_file:
10+
bot.evn
911
restart:
1012
on-failure
1113
volumes:
@@ -23,7 +25,6 @@ services:
2325
ports:
2426
- 5432:5432
2527

26-
2728
redis:
2829
container_name: redis
2930
image:
@@ -40,6 +41,30 @@ services:
4041
- ../data/redis:/data
4142
restart: always
4243

44+
influxdb:
45+
image: influxdb:1.8-alpine
46+
container_name: "influxdb"
47+
restart: always
48+
volumes:
49+
- "influxdb:/var/lib/influxdb"
50+
environment: # см. файл .env (в репозитории - .env_dist)
51+
- INFLUXDB_DB=${DB}
52+
- INFLUXDB_ADMIN_USER=${DB_ADMIN_USER} # Этот юзер нужен для создания базы
53+
- INFLUXDB_ADMIN_USER_PASSWORD=${DB_ADMIN_PASS}
54+
- INFLUXDB_USER=${DB_USER} # Этот юзер для записи в БД и чтения со стороны Grafana
55+
- INFLUXDB_USER_PASSWORD=${DB_PASS}
56+
- INFLUXDB_HTTP_AUTH_ENABLED=true
57+
58+
grafana:
59+
image: grafana/grafana:7.3.4
60+
container_name: "grafana"
61+
volumes:
62+
- "grafana-data:/var/lib/grafana"
63+
environment:
64+
- GF_DATE_FORMATS_DEFAULT_TIMEZONE=browser
65+
ports:
66+
- "3000:3000"
67+
4368
adminer:
4469
image:
4570
adminer

filter.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1+
import os
2+
13
from aiogram import types
24
from aiogram.dispatcher.filters import BoundFilter
3-
import helps
4-
5-
6-
class Base_bot_filter(BoundFilter):
7-
key = 'is_master'
8-
9-
def __init__(self, is_admin=False):
10-
self.is_admin = is_admin
11-
12-
async def check(self, message: types.Message):
13-
pass
145

156

167
class MasterFilter(BoundFilter):
178
key = 'is_master'
189

1910
def __init__(self, is_admin=False):
2011
self.is_admin = is_admin
12+
self.master = os.environ.get("MASTER")
2113

2214
def check(self, message: types.Message):
23-
return message.chat.id == helps.master
15+
return message.chat.id == self.master
16+
17+

handlers/callback_handlers.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,9 @@
33
from aiogram import types
44

55
import helps
6-
from core import posts_cb, proxy_list, Button, dp, pastebin, io_json_box, postgres, proxy_class
6+
from core import posts_cb, dp, pastebin, io_json_box, postgres
77
from modules.db_pg import PastebinTable
8-
9-
10-
@dp.callback_query_handler(posts_cb.filter(action=['edit']))
11-
async def back(query: types.CallbackQuery):
12-
"""
13-
:param query:
14-
:return:
15-
"""
16-
if len(proxy_list) < 1:
17-
[proxy_list.append(i) for i in await proxy_class.main()]
18-
19-
await query.message.edit_text(text=helps.mes["new_proxy"],
20-
reply_markup=Button.edit_proxy(text_button="не работает?", proxy=proxy_list[0],
21-
callback="edit"))
22-
proxy_list.pop(0)
8+
from modules.stat import detect, Command
239

2410

2511
@dp.callback_query_handler(posts_cb.filter(action=["pastebin"]))
@@ -35,7 +21,7 @@ async def pastebin_(query: types.CallbackQuery) -> None:
3521
async def json_box(query: types.CallbackQuery):
3622
await postgres.connect(helps.POSTGRES)
3723
text = await PastebinTable.select("paste").where(PastebinTable.chat_id == query.message.chat.id).gino.scalar()
38-
print(text)
3924
await query.message.edit_text(await io_json_box.create_box(
4025
text=text))
4126
await text.delete()
27+
await detect(query.from_user.id, Command.JSONBOX)

handlers/inline_handlers.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from aiogram.types import InlineQuery, \
66
InputTextMessageContent, InlineQueryResultArticle
77

8-
from core import dp, bot, lazy_get_text, cb as bank_api, crypto_price, proxy_class, Button
8+
from core import dp, bot, lazy_get_text, cb as bank_api, crypto_price, Button
99

1010

1111
@dp.inline_handler()
@@ -56,19 +56,7 @@ async def inline_echo(inline_query: InlineQuery) -> InlineQueryResultArticle:
5656
title=lazy_get_text('{name} {price} btc ').format(name=text, price=(1 / price)),
5757
input_message_content=input_content
5858
)
59-
elif text == "proxy":
60-
proxy_url = await proxy_class.main()
61-
62-
input_content = InputTextMessageContent(f"proxy for you {proxy_url[0]}")
63-
64-
item = InlineQueryResultArticle(
65-
id=result_id,
66-
title=f"{proxy_url[0]}",
67-
input_message_content=input_content,
68-
reply_markup=Button.proxy(proxy_url)
69-
)
7059
else:
71-
7260
input_content = InputTextMessageContent(
7361
lazy_get_text("нет такой валюты\nдоступные {name}").format(name=list(res.keys())))
7462
result_id: str = hashlib.md5(text.encode()).hexdigest()
@@ -77,7 +65,5 @@ async def inline_echo(inline_query: InlineQuery) -> InlineQueryResultArticle:
7765
title=lazy_get_text("нет такой валюты"),
7866
input_message_content=input_content
7967
)
80-
8168
result_list.append(item)
82-
8369
return await bot.answer_inline_query(inline_query.id, results=result_list, cache_time=1)

0 commit comments

Comments
 (0)