Skip to content

Commit

Permalink
Finally done
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgojoof6eyes committed Oct 4, 2023
1 parent 7439fbb commit 9de4c04
Show file tree
Hide file tree
Showing 42 changed files with 991 additions and 421 deletions.
40 changes: 4 additions & 36 deletions Powers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import pyrogram
import pytz

from Powers.database.support_db import SUPPORTS

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

Expand Down Expand Up @@ -79,7 +77,6 @@
LOGGER.info(f"Time zone set to {Config.TIME_ZONE}")
LOGGER.info("Source Code: https://github.com/Gojo-Bots/Gojo_Satoru\n")
LOGGER.info("Checking lyrics genius api...")
LOGGER.info("Initialising telegraph client")

# API based clients
if Config.GENIUS_API_TOKEN:
Expand Down Expand Up @@ -135,39 +132,6 @@
DEVS = DEVS_USER | Defult_dev
DEV_USERS = list(DEVS)

async def load_support_users():
support = SUPPORTS()
for i in DEV_USERS:
support.insert_support_user(int(i),"dev")
for i in SUDO_USERS:
support.insert_support_user(int(i),"sudo")
for i in WHITELIST_USERS:
support.insert_support_user(int(i),"whitelist")
return

def get_support_staff(want = "all"):
"""
dev, sudo, whitelist, dev_level, sudo_level, all
"""
support = SUPPORTS()
devs = support.get_particular_support("dev")
sudo = support.get_particular_support("sudo")
whitelist = support.get_particular_support("whitelist")

if want == "dev":
return devs
elif want == "sudo":
return sudo
elif want == "whitelist":
return whitelist
elif want == "dev_level":
return devs
elif want == "sudo_level":
return sudo + devs
else:
return list(set([int(OWNER_ID)] + devs + sudo + whitelist))


# Plugins, DB and Workers
DB_URI = Config.DB_URI
DB_NAME = Config.DB_NAME
Expand All @@ -176,10 +140,14 @@ def get_support_staff(want = "all"):
BDB_URI = Config.BDB_URI

# Prefixes
PREFIX_HANDLER = Config.PREFIX_HANDLER

HELP_COMMANDS = {} # For help menu
UPTIME = time() # Check bot uptime

from apscheduler.schedulers.asyncio import AsyncIOScheduler

scheduler = AsyncIOScheduler(timezone=TIME_ZONE)

async def load_cmds(all_plugins):
"""Loads all the plugins in bot."""
Expand Down
1 change: 1 addition & 0 deletions Powers/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
# uvloop.install() # Comment it out if using on windows
Gojo().run()


20 changes: 8 additions & 12 deletions Powers/bot_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
from threading import RLock
from time import gmtime, strftime, time

from apscheduler.schedulers.asyncio import AsyncIOScheduler
from pyrogram import Client, __version__
from pyrogram.raw.all import layer
from pyrogram.types import BotCommand

from Powers import (API_HASH, API_ID, BDB_URI, BOT_TOKEN, LOG_DATETIME,
LOGFILE, LOGGER, MESSAGE_DUMP, NO_LOAD, OWNER_ID,
TIME_ZONE, UPTIME, WORKERS, load_cmds, load_support_users)
LOGFILE, LOGGER, MESSAGE_DUMP, NO_LOAD, OWNER_ID, UPTIME,
WORKERS, load_cmds, scheduler)
from Powers.database import MongoDB
from Powers.plugins import all_plugins
from Powers.plugins.birthday import send_wishish
from Powers.plugins.clean_db import clean_my_db
from Powers.plugins.scheduled_jobs import *
from Powers.supports import *
from Powers.vars import Config

scheduler = AsyncIOScheduler(timezone=TIME_ZONE)

INITIAL_LOCK = RLock()

# Check if MESSAGE_DUMP is correct
Expand Down Expand Up @@ -59,10 +56,6 @@ async def start(self):
Config.BOT_ID = meh.id
Config.BOT_NAME = meh.first_name
Config.BOT_USERNAME = meh.username
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.start()
startmsg = await self.send_message(MESSAGE_DUMP, "<i>Starting Bot...</i>")

# Show in Log that bot has started
Expand All @@ -75,7 +68,10 @@ async def start(self):
cmd_list = await load_cmds(await all_plugins())
await load_support_users()
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.start()
# Send a message to MESSAGE_DUMP telling that the
# bot has started and has loaded all plugins!
await startmsg.edit_text(
Expand Down
11 changes: 5 additions & 6 deletions Powers/database/afk_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ 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=0):
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})
self.update({"chat_id":chat_id,"user_id":user_id},{"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})
return
self.update({"chat_id":chat_id,"user_id":user_id},{'media':media,'media_type':media_type,"time":time})
return True
else:
self.insert_one(
{
Expand All @@ -34,7 +33,7 @@ def insert_afk(self, chat_id, user_id, time, reason, media_type,media=0):
"media_type":media_type
}
)
return
return True

def check_afk(self, chat_id, user_id):
curr = self.find_one({"chat_id":chat_id,"user_id":user_id})
Expand Down
50 changes: 50 additions & 0 deletions Powers/database/autojoin_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from threading import RLock
from time import time

from Powers import LOGGER
from Powers.database import MongoDB

INSERTION_LOCK = RLock()


class AUTOJOIN(MongoDB):
"""class to store auto join requests"""

db_name = "autojoin"

def __init__(self) -> None:
super().__init__(self.db_name)

def load_autojoin(self, chat,mode="auto"):
"""
type = auto or notify
auto to auto accept join requests
notify to notify the admins about the join requests
"""
curr = self.find_one({"chat_id":chat,})
if not curr:
with INSERTION_LOCK:
self.insert_one({"chat_id":chat,"type":mode})
return True
return False

def get_autojoin(self,chat):
curr = self.find_one({"chat_id":chat})
if not curr:
return False
else:
return curr["type"]

def update_join_type(self,chat,mode):
curr = self.find_one({"chat_id":chat})
if curr:
self.update({"chat_id":chat},{"type":mode})
return
else:
return

def remove_autojoin(self,chat):
curr = self.find_one({"chat_id":chat})
if curr:
self.delete_one({"chat_id":chat})
return
72 changes: 71 additions & 1 deletion Powers/database/locks_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,74 @@ class LOCKS(MongoDB):
db_name = "locks"

def __init__(self) -> None:
super().__init__(self.db_name)
super().__init__(self.db_name)

def insert_lock_channel(self, chat: int, locktype: str):
"""
locktypes: anti_c_send, anti_fwd, anti_fwd_u, anti_fwd_c, anti_links
"""
curr = self.find_one({"chat_id":chat,"locktype":locktype})
if curr:
return False
else:
with INSERTION_LOCK:
hmm = self.merge_u_and_c(chat,locktype)
if not hmm:
self.insert_one({"chat_id":chat,"locktype":locktype})
return True

def remove_lock_channel(self, chat: int, locktype: str):
"""
locktypes: anti_c_send, anti_fwd, anti_fwd_u, anti_fwd_c, anti_links
"""
curr = self.find_one({"chat_id":chat,"locktype":locktype})
if curr:
with INSERTION_LOCK:
self.delete_one({"chat_id":chat,"locktype":locktype})
return True
else:
return False

def get_lock_channel(self, locktype: str="all"):
"""
locktypes: anti_c_send, anti_fwd, anti_fwd_u, anti_fwd_c, anti_links
"""
if locktype not in ["anti_c_send","anti_fwd","anti_fwd_u","anti_fwd_c","anti_links", "all"]:
return False
else:
if locktype == "all":
find = {}
else:
find = {"locktype":locktype}
curr = self.find_all(find)
if not curr:
list_ = []
else:
list_ = [i["chat_id"] for i in curr]
return list_

def merge_u_and_c(self, chat: int, locktype: str):
if locktype == "anti_fwd_u":
curr = self.find_one({"chat_id":chat,"locktype":"anti_fwd_c"})
elif locktype == "anti_fwd_c":
curr = self.find_one({"chat_id":chat,"locktype":"anti_fwd_u"})
else:
return False

if curr:
self.delete_one({"chat_id":chat,"locktype":locktype})
self.insert_one({"chat_id":chat,"locktype":"anti_fwd"})
return True
else:
return False

def is_particular_lock(self, chat: int, locktype: str):
"""
locktypes: anti_c_send, anti_fwd, anti_fwd_u, anti_fwd_c, anti_links
"""
curr = self.find_one({"chat_id":chat,"locktype":locktype})
if curr:
return True
else:
return False

2 changes: 1 addition & 1 deletion Powers/database/support_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def delete_support_user(self,user):
def get_particular_support(self,support_type):
curr = self.find_all({"support_type":support_type})
if curr:
return curr
return [i['user_id'] for i in curr]
else:
return []

Expand Down
3 changes: 2 additions & 1 deletion Powers/plugins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
UserAdminInvalid)
from pyrogram.types import ChatPrivileges, Message

from Powers import LOGGER, OWNER_ID, get_support_staff
from Powers import LOGGER, OWNER_ID
from Powers.bot_class import Gojo
from Powers.database.approve_db import Approve
from Powers.database.reporting_db import Reporting
from Powers.supports import get_support_staff
from Powers.utils.caching import (ADMIN_CACHE, TEMP_ADMIN_CACHE_BLOCK,
admin_cache_reload)
from Powers.utils.custom_filters import (admin_filter, command, owner_filter,
Expand Down
Loading

0 comments on commit 9de4c04

Please sign in to comment.