Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/pytz-2024.1
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgojoof6eyes authored Nov 13, 2024
2 parents bec6db6 + dc3f3f4 commit 3ac2a0c
Show file tree
Hide file tree
Showing 81 changed files with 3,126 additions and 1,550 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit-autoupdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Run pre-commit autoupdate
run: pre-commit autoupdate
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-autoupdate
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
*.session
*.session-journal
Powers/config.py
Powers/vars.py
.vscode/
postgres-data/
*.env
!sample.env
logs/
Powers/local_vars.py
Powers/vars.py
.idea/
scrapped/

# Byte-compiled / optimized / DLL files
__pycache__/
Youtube/
*.py[cod]
*$py.class

Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -12,7 +12,7 @@ repos:
- id: check-merge-conflict

- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.10.0
hooks:
- id: black
language_version: python3
Expand All @@ -24,7 +24,7 @@ repos:
args: [--py36-plus]

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py36-plus]
Expand Down
71 changes: 41 additions & 30 deletions Powers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import shutil
from datetime import datetime
from importlib import import_module as imp_mod
from logging import (INFO, WARNING, FileHandler, StreamHandler, basicConfig,
getLogger)
from os import environ, listdir, mkdir, path
from platform import python_version
from random import choice
from sys import exit as sysexit
from sys import stdout, version_info
from time import time
Expand All @@ -13,13 +13,17 @@
import lyricsgenius
import pyrogram
import pytz
from apscheduler.schedulers.asyncio import AsyncIOScheduler

LOG_DATETIME = datetime.now().strftime("%d_%m_%Y-%H_%M_%S")
LOGDIR = f"{__name__}/logs"

# Make Logs directory if it does not exixts
if not path.isdir(LOGDIR):
mkdir(LOGDIR)
else:
shutil.rmtree(LOGDIR)
mkdir(LOGDIR)

LOGFILE = f"{LOGDIR}/{__name__}_{LOG_DATETIME}_log.txt"

Expand Down Expand Up @@ -47,20 +51,21 @@

# the secret configuration specific things
try:
if environ.get("ENV"):
from Powers.vars import is_env
if is_env or environ.get("ENV"):
from Powers.vars import Config
else:
from Powers.vars import Development as Config
except Exception as ef:
LOGGER.error(ef) # Print Error
LOGGER.error(format_exc())
sysexit(1)
#time zone
# time zone
TIME_ZONE = pytz.timezone(Config.TIME_ZONE)

path = "./Version"
Vpath = "./Version"
version = []
for i in listdir(path):
for i in listdir(Vpath):
if i.startswith("version") and i.endswith("md"):
version.append(i)
else:
Expand Down Expand Up @@ -92,16 +97,16 @@
genius_lyrics.verbose = False
LOGGER.info("Client setup complete")
elif not Config.GENIUS_API_TOKEN:
LOGGER.error("Genius api not found lyrics command will not work")
LOGGER.info("Genius api not found lyrics command will not work")
is_genius_lyrics = False
genius_lyrics = False

is_audd = False
Audd = None
if Config.AuDD_API:
is_audd = True
Audd = Config.AuDD_API
LOGGER.info("Found Audd api")
# is_audd = False
# Audd = None
# if Config.AuDD_API:
# is_audd = True
# Audd = Config.AuDD_API
# LOGGER.info("Found Audd api")

is_rmbg = False
RMBG = None
Expand All @@ -114,25 +119,15 @@
API_HASH = Config.API_HASH

# General Config
MESSAGE_DUMP = Config.MESSAGE_DUMP
MESSAGE_DUMP = Config.MESSAGE_DUMP if Config.MESSAGE_DUMP else Config.OWNER_ID
SUPPORT_GROUP = Config.SUPPORT_GROUP
SUPPORT_CHANNEL = Config.SUPPORT_CHANNEL

# Users Config
# Users Config
OWNER_ID = Config.OWNER_ID
DEV = Config.DEV_USERS
DEVS_USER = set(DEV)
SUDO_USERS = Config.SUDO_USERS
WHITELIST_USERS = Config.WHITELIST_USERS



defult_dev = [1344569458, 1432756163, 5294360309] + [int(OWNER_ID)]

Defult_dev = set(defult_dev)

DEVS = DEVS_USER | Defult_dev
DEV_USERS = list(DEVS)
DEV_USERS = set(Config.DEV_USERS)
SUDO_USERS = set(Config.SUDO_USERS)
WHITELIST_USERS = set(Config.WHITELIST_USERS)

# Plugins, DB and Workers
DB_URI = Config.DB_URI
Expand All @@ -147,16 +142,31 @@
HELP_COMMANDS = {} # For help menu
UPTIME = time() # Check bot uptime

from apscheduler.schedulers.asyncio import AsyncIOScheduler

#Make dir
youtube_dir = "./Youtube/"
if not path.isdir(youtube_dir):
mkdir(youtube_dir)
else:
shutil.rmtree(youtube_dir)
mkdir(youtube_dir)

scrap_dir = "./scrapped/"
if not path.isdir(scrap_dir):
mkdir(scrap_dir)
else:
shutil.rmtree(scrap_dir)
mkdir(scrap_dir)
scheduler = AsyncIOScheduler(timezone=TIME_ZONE)


async def load_cmds(all_plugins):
"""Loads all the plugins in bot."""
for single in all_plugins:
# If plugin in NO_LOAD, skip the plugin
if single.lower() in [i.lower() for i in Config.NO_LOAD]:
LOGGER.warning(f"Not loading '{single}' s it's added in NO_LOAD list")
LOGGER.warning(
f"Not loading '{single}' s it's added in NO_LOAD list")
continue

imported_module = imp_mod(f"Powers.plugins.{single}")
Expand Down Expand Up @@ -197,6 +207,7 @@ async def load_cmds(all_plugins):
LOGGER.warning(f"Not loading Plugins - {NO_LOAD}")

return (
", ".join((i.split(".")[1]).capitalize() for i in list(HELP_COMMANDS.keys()))
", ".join((i.split(".")[1]).capitalize()
for i in list(HELP_COMMANDS.keys()))
+ "\n"
)
6 changes: 2 additions & 4 deletions Powers/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import uvloop # Comment it out if using on windows
# import uvloop # Comment it out if using on windows
from Powers.bot_class import Gojo

if __name__ == "__main__":
uvloop.install() # Comment it out if using on windows
# uvloop.install() # Comment it out if using on windows
Gojo().run()


32 changes: 16 additions & 16 deletions Powers/bot_class.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from platform import python_version
from threading import RLock
from time import gmtime, strftime, time
from time import gmtime, strftime
from time import time as t

from pyrogram import Client, __version__
from pyrogram.raw.all import layer
Expand All @@ -24,7 +25,6 @@
)



class Gojo(Client):
"""Starts the Pyrogram Client on the Bot Token when we do 'python3 -m Powers'"""

Expand All @@ -45,10 +45,11 @@ async def start(self):
await super().start()
await self.set_bot_commands(
[
BotCommand("start", "To check weather the bot is alive or not"),
BotCommand(
"start", "To check weather the bot is alive or not"),
BotCommand("help", "To get help menu"),
BotCommand("donate", "To buy me a coffee"),
BotCommand("bug","To report bugs")
BotCommand("bug", "To report bugs")
]
)
meh = await self.get_me() # Get bot info from pyrogram client
Expand All @@ -67,10 +68,11 @@ async def start(self):
# Get cmds and keys
cmd_list = await load_cmds(await all_plugins())
await load_support_users()
await cache_support()
LOGGER.info(f"Plugins Loaded: {cmd_list}")
scheduler.add_job(clean_my_db,'cron',[self],hour=3,minute=0,second=0)
if BDB_URI:
scheduler.add_job(send_wishish,'cron',[self],hour=0,minute=0,second=0)
scheduler.add_job(send_wishish, 'cron', [
self], hour=0, minute=0, second=0)
scheduler.start()
# Send a message to MESSAGE_DUMP telling that the
# bot has started and has loaded all plugins!
Expand All @@ -87,24 +89,22 @@ async def start(self):

async def stop(self):
"""Stop the bot and send a message to MESSAGE_DUMP telling that the bot has stopped."""
runtime = strftime("%Hh %Mm %Ss", gmtime(time() - UPTIME))
runtime = strftime("%Hh %Mm %Ss", gmtime(t() - UPTIME))
LOGGER.info("Uploading logs before stopping...!\n")
# Send Logs to MESSAGE_DUMP and LOG_CHANNEL
scheduler.remove_all_jobs()
if MESSAGE_DUMP:
# LOG_CHANNEL is not necessary
target = MESSAGE_DUMP
else:
target = OWNER_ID
await self.send_document(
MESSAGE_DUMP,
target,
document=LOGFILE,
caption=(
"Bot Stopped!\n\n" f"Uptime: {runtime}\n" f"<code>{LOG_DATETIME}</code>"
),
)
scheduler.remove_all_jobs()
if MESSAGE_DUMP:
# LOG_CHANNEL is not necessary
await self.send_document(
MESSAGE_DUMP,
document=LOGFILE,
caption=f"Uptime: {runtime}",
)
await super().stop()
MongoDB.close()
LOGGER.info(
Expand Down
34 changes: 18 additions & 16 deletions Powers/database/afk_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,45 @@ class AFK(MongoDB):
def __init__(self) -> None:
super().__init__(self.db_name)

def insert_afk(self, chat_id, user_id, time, reason, media_type,media=None):
def insert_afk(self, chat_id, user_id, time, reason, media_type, media=None):
with INSERTION_LOCK:
curr = self.check_afk(chat_id=chat_id, user_id=user_id)
if curr:
if reason:
self.update({"chat_id":chat_id,"user_id":user_id},{"reason":reason,"time":time})
self.update({"chat_id": chat_id, "user_id": user_id}, {
"reason": reason, "time": time})
if media:
self.update({"chat_id":chat_id,"user_id":user_id},{'media':media,'media_type':media_type,"time":time})
self.update({"chat_id": chat_id, "user_id": user_id}, {
'media': media, 'media_type': media_type, "time": time})
return True
else:
self.insert_one(
{
"chat_id":chat_id,
"user_id":user_id,
"reason":reason,
"time":time,
"media":media,
"media_type":media_type
"chat_id": chat_id,
"user_id": user_id,
"reason": reason,
"time": time,
"media": media,
"media_type": media_type
}
)
return True

def check_afk(self, chat_id, user_id):
curr = self.find_one({"chat_id":chat_id,"user_id":user_id})
curr = self.find_one({"chat_id": chat_id, "user_id": user_id})
if curr:
return True
return False

def get_afk(self, chat_id, user_id):
curr = self.find_one({"chat_id":chat_id,"user_id":user_id})
curr = self.find_one({"chat_id": chat_id, "user_id": user_id})
if curr:
return curr
return

def delete_afk(self, chat_id, user_id):
with INSERTION_LOCK:
curr = self.check_afk(chat_id,user_id)
curr = self.check_afk(chat_id, user_id)
if curr:
self.delete_one({"chat_id":chat_id,"user_id":user_id})
return
self.delete_one({"chat_id": chat_id, "user_id": user_id})
return
3 changes: 2 additions & 1 deletion Powers/database/antispam_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def add_gban(self, user_id: int, reason: str, by_user: int):
return self.update_gban_reason(user_id, reason)

# If not already gbanned, then add to gban
ANTISPAM_BANNED.add(user_id)
time_rn = datetime.now(TZ)
return self.insert_one(
{
Expand All @@ -43,8 +44,8 @@ def remove_gban(self, user_id: int):
with INSERTION_LOCK:
# Check if user is already gbanned or not
if self.find_one({"_id": user_id}):
ANTISPAM_BANNED.remove(user_id)
return self.delete_one({"_id": user_id})

return "User not gbanned!"

def get_gban(self, user_id: int):
Expand Down
Loading

0 comments on commit 3ac2a0c

Please sign in to comment.