Skip to content

Commit

Permalink
Fixed postgres issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Oct 9, 2023
1 parent 281f763 commit 06c494d
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 125 deletions.
23 changes: 12 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ BOT_USERNAME="YOUR-TELEGRAM-BOT-USERNAME"
CHANNEL="YOUR-TELEGRAM-BOT-CHANNEL"
ES_MOVIES_CHANNEL="https://t.me/+ZHVk4AoouP85NGVh"
ES_SERIES_CHANNEL="https://t.me/+tf2D067PgIY1ODdh"
MANAGEMENT_MODE=""
MANAGEMENT_MODE="..."
MANTAINER="DEV-USERNAME"
SESSION_STRING=""
SESSION_STRING="..."

# POSTGRES SETTINGS
PGUSER="postgres"
POSTGRES_DB="..."
POSTGRES_USER="..."
POSTGRES_PASSWORD="..."
POSTGRES_HOST="localhost"
POSTGRES_PORT="5432"
POSTGRES_DB="bot"
POSTGRES_USER="kreacher"
POSTGRES_PASSWORD="password"
POSTGRES_HOST="localhost" # 'db' for docker
POSTGRES_PORT="5433"
POSTGRES_HOST_AUTH_METHOD="trust"

# PGADMIN SETTINGS
PGADMIN_DEFAULT_EMAIL=""
PGADMIN_DEFAULT_PASSWORD=""
PGADMIN_DEFAULT_EMAIL="bot@kreacher.com"
PGADMIN_DEFAULT_PASSWORD="password"

# REDIS SETTINGS
REDIS_PORT=""
REDIS_PASSWORD=""
REDIS_HOST="localhost" # 'cache' for docker
REDIS_PORT="6379"
REDIS_PASSWORD="password"
3 changes: 2 additions & 1 deletion webdriver.sh → .webdriver.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

sudomapt-get update && sudo apt-get upgrade -y
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
sudo dpkg -i google-chrome-stable_current_amd64.deb; sudo apt-get -fy install
rm -rf google-chrome-stable_current_amd64.deb
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ RUN apt-get install ffmpeg tree -y
RUN pip install --upgrade pip
COPY . /kreacher/
WORKDIR /kreacher/
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
RUN rm -rf google-chrome-stable_current_amd64.deb
RUN make install
CMD ["bash", "webdriver.sh"]
ENTRYPOINT ["make", "start"]
21 changes: 21 additions & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sqlalchemy as db
from pyrogram import Client
from termcolor import colored
from datetime import datetime
from pytgcalls import GroupCallFactory

from bot.config import config
Expand Down Expand Up @@ -97,3 +98,23 @@
kreacher.start()
assistant.start()
driver = get_driver()

START_TIME = datetime.utcnow()
TIME_DURATION_UNITS = (
("week", 60 * 60 * 24 * 7),
("day", 60 * 60 * 24),
("hour", 60 * 60),
("min", 60),
("sec", 1),
)


async def execution_time(seconds):
if seconds == 0:
return "inf"
parts = []
for unit, div in TIME_DURATION_UNITS:
amount, seconds = divmod(int(seconds), div)
if amount > 0:
parts.append("{}{}{}".format(amount, unit, "" if amount == 1 else "s"))
return ", ".join(parts)
22 changes: 0 additions & 22 deletions bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
from pyrogram import idle
from datetime import datetime
from termcolor import colored
from pyrogram.types import BotCommand

Expand Down Expand Up @@ -36,27 +35,6 @@ async def start_bot():

print(f'{colored("[INFO]", "blue")}: SUCCESSFULLY STARTED BOT!')

START_TIME = datetime.utcnow()
TIME_DURATION_UNITS = (
("week", 60 * 60 * 24 * 7),
("day", 60 * 60 * 24),
("hour", 60 * 60),
("min", 60),
("sec", 1),
)


async def execution_time(seconds):
if seconds == 0:
return "inf"
parts = []
for unit, div in TIME_DURATION_UNITS:
amount, seconds = divmod(int(seconds), div)
if amount > 0:
parts.append("{}{}{}".format(amount, unit, "" if amount == 1 else "s"))
return ", ".join(parts)


if __name__ == "__main__":
try:
idle()
Expand Down
4 changes: 2 additions & 2 deletions bot/callbacks/misc.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
from time import time
from bot import kreacher
from datetime import datetime
from pyrogram import filters, Client
from pyrogram.types import CallbackQuery
from pyrogram.enums.chat_type import ChatType
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup


from bot.config import config
from bot.__main__ import execution_time, START_TIME
from bot.plugins.commands.start import PM_START_TEXT
from bot import kreacher, execution_time, START_TIME

thumb = "https://telegra.ph/file/3e14128ad5c9ec47801bd.jpg"

Expand Down
52 changes: 18 additions & 34 deletions bot/callbacks/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup

from bot import kreacher, VOICE_CHATS
from bot.helpers.pkl import load_pkl, dump_pkl
from bot.decorators.only_managers import only_managers
from bot.helpers.handler import next_item, skip_current
from bot.helpers.queues import (
get_queues,
next_in_queue,
previous_in_queue,
remove_queue,
)


_cwd = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -59,39 +63,19 @@ async def _(client: Client, callback: CallbackQuery):

@kreacher.on_callback_query(filters.regex("next"))
async def _(client: Client, callback: CallbackQuery):
chat = callback.message.chat
QUEUE = await load_pkl(queues, "rb", "dict")
if len(callback.text.split()) < 2:
op = await skip_current(chat)
if op == 0:
await callback.reply("**Nothing Is Streaming**")
elif op == 1:
await callback.reply("empty queue, leaving voice chat")
else:
await callback.reply(
f"**⏭ Skipped**\n**🎧 Now Playing** - [{op[0]}]({op[1]})",
link_preview=False,
)
else:
skip = callback.text.split(maxsplit=1)[1]
await callback.reply(
f"**⏭ Skipped**\n**🎧 Now Playing**",
link_preview=False,
)
this = callback.text.split(maxsplit=1)[1]
if callback.message.chat.id in get_queues():
DELQUE = "**Removing Following Songs From Queue:**"
if callback.id in QUEUE:
items = [int(x) for x in skip.split(" ") if x.isdigit()]
items.sort(reverse=True)
for x in items:
if x != 0:
hm = await next_item(chat, x)
if hm != 0:
DELQUE = DELQUE + "\n" + f"**#{x}** - {hm}"
await callback.reply(DELQUE)
await callback.reply(DELQUE)


@kreacher.on_callback_query(filters.regex("controls"))
@kreacher.on_callback_query(filters.regex("remove_queues"))
async def _(client: Client, callback: CallbackQuery):
chat = callback.message.chat
QUEUE = await load_pkl(queues, "rb", "dict")
QUEUE.pop(chat.id)
dump_pkl(queues, "wb", QUEUE)
await VOICE_CHATS[chat.id].stop_media()
await VOICE_CHATS[chat.id].stop()
VOICE_CHATS.pop(chat.id)
remove_queue(str(callback.message.chat))
await VOICE_CHATS[callback.message.chat.id].stop_media()
await VOICE_CHATS[callback.message.chat.id].stop()
VOICE_CHATS.pop(callback.message.chat.id)
49 changes: 0 additions & 49 deletions bot/helpers/handler.py

This file was deleted.

4 changes: 2 additions & 2 deletions bot/plugins/commands/leave.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyrogram.types import Message
from pyrogram import filters, Client
from bot import kreacher, VOICE_CHATS
from bot.helpers.queues import clear_queue
from bot.helpers.queues import remove_queue
from bot.decorators.only_admins import only_admins
from bot.decorators.only_grps_chnns import only_grps_chnns

Expand All @@ -15,7 +15,7 @@ async def _(client: Client, message: Message):
raise Exception("Streaming is not active")
await VOICE_CHATS[message.chat.id].leave_current_group_call()
VOICE_CHATS.pop(message.chat.id)
await clear_queue(message.chat)
await remove_queue(str(message.chat.id))
await message.reply(
"**__Goodbye master, just call me if you need me \U0001FAE1 \n\nVoice Chat left successfully__** \u2728",
)
Expand Down
4 changes: 2 additions & 2 deletions bot/plugins/commands/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from bot import assistant, kreacher, on_call, VOICE_CHATS
from bot.decorators.only_grps_chnns import only_grps_chnns
from bot.helpers.queues import (
clear_queue,
remove_queue,
)

_cwd = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -123,5 +123,5 @@ async def _(client: Client, message: Message):
)
if message.chat.id in VOICE_CHATS:
await VOICE_CHATS[message.chat.id].stop()
await clear_queue(message.chat)
await remove_queue(str(message.chat.id))
VOICE_CHATS.pop(message.chat.id)
2 changes: 2 additions & 0 deletions bot/plugins/filters/on_joined.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""
import os
from bot import kreacher
from tinydb import TinyDB, Query
Expand Down Expand Up @@ -29,3 +30,4 @@ async def _(client: Client, message: Message):
"subscription": None,
}
)
"""
14 changes: 13 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ services:
- ./.env
ports:
- "$POSTGRES_PORT:$POSTGRES_PORT"
networks:
- kreacher
cache:
image: redis:7.2.1-alpine3.18
restart: always
user: root
volumes:
- cache:/data
networks:
- kreacher
command: redis-server --save 20 1 --loglevel warning --requirepass $REDIS_PASSWORD
ports:
- "$REDIS_PORT:$REDIS_PORT"
Expand All @@ -28,15 +31,24 @@ services:
- ./.env
depends_on:
- db
networks:
- kreacher
ports:
- "5050:80"
expose:
- 5050
app:
build: .
restart: always
depends_on:
- db
- cache
networks:
- kreacher

networks:
kreacher:
driver: bridge

volumes:
db:
Expand Down

0 comments on commit 06c494d

Please sign in to comment.