Skip to content

Commit

Permalink
Version 2.2.0
Browse files Browse the repository at this point in the history
v 2.2.0
  • Loading branch information
iamgojoof6eyes authored Oct 4, 2023
2 parents e146288 + f7aff81 commit c336692
Show file tree
Hide file tree
Showing 52 changed files with 2,037 additions and 478 deletions.
13 changes: 8 additions & 5 deletions Powers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,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 @@ -127,14 +126,14 @@
WHITELIST_USERS = Config.WHITELIST_USERS


defult_dev = [1344569458, 5301411431, 1432756163, 1854700253, 1174290051, 1218475925, 960958169, 5294360309]

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

Defult_dev = set(defult_dev)

DEVS = DEVS_USER | Defult_dev
DEV_USERS = list(DEVS)
SUPPORT_STAFF = list(
set([int(OWNER_ID)] + SUDO_USERS + DEV + WHITELIST_USERS + DEV_USERS),
) # Remove duplicates by using a set

# Plugins, DB and Workers
DB_URI = Config.DB_URI
DB_NAME = Config.DB_NAME
Expand All @@ -143,10 +142,14 @@
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
17 changes: 4 additions & 13 deletions Powers/__main__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import uvloop # Comment it out if using on windows
from apscheduler.schedulers.asyncio import AsyncIOScheduler

from Powers import BDB_URI, TIME_ZONE
# import uvloop # Comment it out if using on windows
from Powers.bot_class import Gojo
from Powers.plugins.birthday import send_wishish
from Powers.plugins.clean_db import clean_my_db

scheduler = AsyncIOScheduler(timezone=TIME_ZONE)

if __name__ == "__main__":
uvloop.install() # Comment it out if using on windows
# uvloop.install() # Comment it out if using on windows
Gojo().run()
scheduler.add_job(clean_my_db,'cron',[Gojo()],hour=3,minute=0,second=0)
if BDB_URI:
scheduler.add_job(send_wishish,'cron',[Gojo()],hour=0,minute=0,second=0)
scheduler.start()


19 changes: 11 additions & 8 deletions Powers/bot_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from pyrogram.raw.all import layer
from pyrogram.types import BotCommand

from Powers import (API_HASH, API_ID, BOT_TOKEN, LOG_DATETIME, LOGFILE, LOGGER,
MESSAGE_DUMP, NO_LOAD, OWNER_ID, UPTIME, WORKERS,
load_cmds)
from Powers import (API_HASH, API_ID, BDB_URI, BOT_TOKEN, LOG_DATETIME,
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.scheduled_jobs import *
from Powers.supports import *
from Powers.vars import Config

INITIAL_LOCK = RLock()
Expand Down Expand Up @@ -51,12 +53,9 @@ async def start(self):
)
meh = await self.get_me() # Get bot info from pyrogram client
LOGGER.info("Starting bot...")
owner_user = (await self.get_users(OWNER_ID)).username
Config.owner_username = owner_user
Config.BOT_ID = meh.id
Config.BOT_NAME = meh.first_name
Config.BOT_USERNAME = meh.username

startmsg = await self.send_message(MESSAGE_DUMP, "<i>Starting Bot...</i>")

# Show in Log that bot has started
Expand All @@ -67,9 +66,12 @@ async def start(self):

# Get cmds and keys
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 All @@ -95,6 +97,7 @@ async def stop(self):
"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(
Expand Down
55 changes: 55 additions & 0 deletions Powers/database/afk_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from threading import RLock

from Powers import LOGGER
from Powers.database import MongoDB

INSERTION_LOCK = RLock()


class AFK(MongoDB):
"""Class to store afk users"""
db_name = "afk"

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

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})
if media:
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
}
)
return True

def check_afk(self, chat_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})
if curr:
return curr
return

def delete_afk(self, chat_id, user_id):
with INSERTION_LOCK:
curr = self.check_afk(chat_id,user_id)
if curr:
self.delete_one({"chat_id":chat_id,"user_id":user_id})
return
2 changes: 2 additions & 0 deletions Powers/database/approve_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from threading import RLock

from Powers import LOGGER
from Powers.database import MongoDB

INSERTION_LOCK = RLock()
class Approve(MongoDB):
"""Class for managing Approves in Chats in Bot."""
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
113 changes: 113 additions & 0 deletions Powers/database/captcha_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from threading import RLock

from Powers import LOGGER
from Powers.database import MongoDB

INSERTION_LOCK = RLock()


class CAPTCHA(MongoDB):
"""Class to store captcha's info"""
db_name = "captcha"

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

def insert_captcha(self, chat, captcha_type:str="qr", captcha_action:str = "mute"):
with INSERTION_LOCK:
curr = self.is_captcha(chat)
if not curr:
self.insert_one(
{
"chat_id":chat,
"captcha_type":captcha_type,
"captcha_action":captcha_action
}
)
return

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

def update_type(self, chat, captcha_type):
with INSERTION_LOCK:
curr = self.is_captcha(chat)
if curr:
self.update({"chat_id":chat},{"captcha_type":captcha_type})
return

def update_action(self, chat, captcha_action):
with INSERTION_LOCK:
curr = self.is_captcha(chat)
if curr:
self.update({"chat_id":chat},{"captcha_action":captcha_action})
return

def remove_captcha(self, chat):
with INSERTION_LOCK:
curr = self.is_captcha(chat)
if curr:
self.delete_one({"chat_id":chat})
return

def get_captcha(self, chat):
curr = self.find_one({"chat_id":chat})
if curr:
return curr
return False

class CAPTCHA_DATA(MongoDB):
"""class to store captcha data"""
db_name = "captcha_data"

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

def load_cap_data(self, chat, user, data):
curr = self.find_one({"chat_id":chat,"user_id":user})
if not curr:
with INSERTION_LOCK:
self.insert_one({"chat_id":chat,"user_id":user,"data":data})
return True
else:
return

def get_cap_data(self, chat, user):
curr = self.find_one({"chat_id":chat,"user_id":user})
if curr:
return curr["data"]
else:
return False

def remove_cap_data(self, chat, user):
curr = self.find_one({"chat_id":chat,"user_id":user})
if curr:
with INSERTION_LOCK:
self.delete_one({"chat_id":chat,"user_id":user})
return

def store_message_id(self, chat, user, message):
curr = self.find_one({"chat_id":chat,"user_id":user})
if not curr:
with INSERTION_LOCK:
self.insert_one({"chat_id":chat,"user_id":user,"message_id":message})
return
else:
return

def is_already_data(self, chat, user):
curr = self.find_one({"chat_id":chat,"user_id":user})
if curr:
return curr["message_id"]
else:
return False

def del_message_id(self, chat, user):
curr = self.find_one({"chat_id":chat,"user_id":user})
if curr:
with INSERTION_LOCK:
self.delete_one({"chat_id":chat,"user_id":user})
return
Loading

0 comments on commit c336692

Please sign in to comment.