Compare commits
10 Commits
b6c0be0d00
...
4a077e1db9
Author | SHA1 | Date | |
---|---|---|---|
4a077e1db9 | |||
0df4950b8e | |||
a7498523b3 | |||
413639c4ed | |||
426a523a47 | |||
765727f112 | |||
6871faf96c | |||
6cc712e3b6 | |||
c3bccf0c71 | |||
7c730cd831 |
@ -20,6 +20,23 @@ services:
|
|||||||
parallelism: 1
|
parallelism: 1
|
||||||
order: start-first
|
order: start-first
|
||||||
|
|
||||||
|
updater:
|
||||||
|
image: mathwave/sprint-repo:pizda-bot
|
||||||
|
command: updater
|
||||||
|
environment:
|
||||||
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
|
||||||
|
MONGO_HOST: "mongo.develop.sprinthub.ru"
|
||||||
|
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
||||||
|
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
||||||
|
STAGE: "development"
|
||||||
|
deploy:
|
||||||
|
mode: replicated
|
||||||
|
restart_policy:
|
||||||
|
condition: any
|
||||||
|
update_config:
|
||||||
|
parallelism: 1
|
||||||
|
order: start-first
|
||||||
|
|
||||||
pizda-bot-nginx:
|
pizda-bot-nginx:
|
||||||
image: mathwave/sprint-repo:pizda-bot
|
image: mathwave/sprint-repo:pizda-bot
|
||||||
command: api
|
command: api
|
||||||
|
@ -20,6 +20,23 @@ services:
|
|||||||
parallelism: 1
|
parallelism: 1
|
||||||
order: start-first
|
order: start-first
|
||||||
|
|
||||||
|
updater:
|
||||||
|
image: mathwave/sprint-repo:pizda-bot
|
||||||
|
command: updater
|
||||||
|
environment:
|
||||||
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD
|
||||||
|
MONGO_HOST: "mongo.sprinthub.ru"
|
||||||
|
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
|
||||||
|
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
||||||
|
STAGE: "production"
|
||||||
|
deploy:
|
||||||
|
mode: replicated
|
||||||
|
restart_policy:
|
||||||
|
condition: any
|
||||||
|
update_config:
|
||||||
|
parallelism: 1
|
||||||
|
order: start-first
|
||||||
|
|
||||||
pizda-bot-nginx:
|
pizda-bot-nginx:
|
||||||
image: mathwave/sprint-repo:pizda-bot
|
image: mathwave/sprint-repo:pizda-bot
|
||||||
command: api
|
command: api
|
||||||
|
35
main.py
35
main.py
@ -1,3 +1,4 @@
|
|||||||
|
import datetime
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from random import randrange, choice
|
from random import randrange, choice
|
||||||
@ -61,6 +62,35 @@ def show_rating(message: Message):
|
|||||||
bot.send_message(message.chat.id, text)
|
bot.send_message(message.chat.id, text)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['point'])
|
||||||
|
def point(message: Message):
|
||||||
|
if not message.reply_to_message:
|
||||||
|
bot.reply_to(message, 'Чтобы начислить Ебаллы, нужно прописать команду ответом на чье-то сообщение')
|
||||||
|
return
|
||||||
|
username = message.reply_to_message.from_user.username
|
||||||
|
if username == get_self_name():
|
||||||
|
bot.reply_to(message, 'Ты конченый? Как я себе Ебаллы то начислю, мудила? Мамке своей Ебаллы начисляй, пидор!')
|
||||||
|
return
|
||||||
|
mongo.inc_points(username, message.chat.id)
|
||||||
|
bot.reply_to(message.reply_to_message, 'Тебе начислили Ебалл!')
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['pointers'])
|
||||||
|
def pointers(message: Message):
|
||||||
|
rating = list(mongo.counter_collection.find({"chat_id": message.chat.id, "points": {"$exists": True}}).sort("points", -1))
|
||||||
|
if not rating:
|
||||||
|
bot.send_message(message.chat.id, "Ебаллы пока никому не начислялись")
|
||||||
|
return
|
||||||
|
text = "Рейтинг Ебальников:\n"
|
||||||
|
rating_arr = list(enumerate(rating))
|
||||||
|
total = 0
|
||||||
|
for _, value in rating_arr:
|
||||||
|
total += value['points']
|
||||||
|
for index, value in rating_arr:
|
||||||
|
text += f"{index + 1}. @{value['username']} - {value['points']}\n"
|
||||||
|
bot.send_message(message.chat.id, text)
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler()
|
@bot.message_handler()
|
||||||
def do_action(message: Message):
|
def do_action(message: Message):
|
||||||
if message.reply_to_message:
|
if message.reply_to_message:
|
||||||
@ -68,6 +98,8 @@ def do_action(message: Message):
|
|||||||
bot.reply_to(message, choice(get_replies()))
|
bot.reply_to(message, choice(get_replies()))
|
||||||
return
|
return
|
||||||
info = get_chat_info(message.chat.id)
|
info = get_chat_info(message.chat.id)
|
||||||
|
if client.get_config('updater')['enabled']:
|
||||||
|
set_values(message.chat.id, last_time_updated=datetime.datetime.now())
|
||||||
if message.text == '#debug' and client.is_staff(telegram_id=message.from_user.id):
|
if message.text == '#debug' and client.is_staff(telegram_id=message.from_user.id):
|
||||||
bot.send_message(message.chat.id, f'chat id: {message.chat.id}\n'
|
bot.send_message(message.chat.id, f'chat id: {message.chat.id}\n'
|
||||||
f'probability: {info["probability"]}')
|
f'probability: {info["probability"]}')
|
||||||
@ -97,6 +129,9 @@ def do_action(message: Message):
|
|||||||
arg = sys.argv[-1]
|
arg = sys.argv[-1]
|
||||||
if arg == 'bot':
|
if arg == 'bot':
|
||||||
bot.polling()
|
bot.polling()
|
||||||
|
elif arg == 'updater':
|
||||||
|
from updater import update
|
||||||
|
update()
|
||||||
else:
|
else:
|
||||||
from api import app
|
from api import app
|
||||||
app.run(host="0.0.0.0", port=1238)
|
app.run(host="0.0.0.0", port=1238)
|
||||||
|
6
mongo.py
6
mongo.py
@ -35,5 +35,11 @@ class Mongo:
|
|||||||
else:
|
else:
|
||||||
self.counter_collection.insert_one({"chat_id": chat_id, "username": username, "count": 1})
|
self.counter_collection.insert_one({"chat_id": chat_id, "username": username, "count": 1})
|
||||||
|
|
||||||
|
def inc_points(self, username, chat_id):
|
||||||
|
if self.counter_collection.find_one({"chat_id": chat_id, "username": username}):
|
||||||
|
self.counter_collection.update_one({"chat_id": chat_id, "username": username}, {"$inc": {"points": 1}})
|
||||||
|
else:
|
||||||
|
self.counter_collection.insert_one({"chat_id": chat_id, "username": username, "points": 1})
|
||||||
|
|
||||||
|
|
||||||
mongo = Mongo()
|
mongo = Mongo()
|
||||||
|
25
updater.py
Normal file
25
updater.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import datetime
|
||||||
|
import random
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
from mongo import mongo
|
||||||
|
|
||||||
|
|
||||||
|
def update():
|
||||||
|
from main import bot, client
|
||||||
|
while True:
|
||||||
|
if client.get_config('updater')['enabled']:
|
||||||
|
fltr = {"last_time_updated": {"$lte": datetime.datetime.now() - datetime.timedelta(seconds=client.get_config('updater')['seconds_delay'])}}
|
||||||
|
if not client.get_config('updater')['send_to_single']:
|
||||||
|
fltr["chat_id"] = {"$lt": 0}
|
||||||
|
for chat in mongo.chats_collection.find(fltr):
|
||||||
|
users = list(mongo.counter_collection.find({"chat_id": chat['chat_id'], 'username': {"$ne": None}}))
|
||||||
|
if not users:
|
||||||
|
continue
|
||||||
|
user = random.choice(users)
|
||||||
|
try:
|
||||||
|
bot.send_message(chat['chat_id'], f"В этом чате давно не было активности, а как говорится, кто молчит - тот трансвестит, а трансвестит сегодня - @{user['username']}")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
mongo.chats_collection.update_one({"chat_id": chat['chat_id']}, {"$set": {"last_time_updated": datetime.datetime.now()}})
|
||||||
|
sleep(client.get_config('updater')['seconds_delay'])
|
Loading…
Reference in New Issue
Block a user