Skip to content

Commit c336692

Browse files
Version 2.2.0
v 2.2.0
2 parents e146288 + f7aff81 commit c336692

52 files changed

Lines changed: 2037 additions & 478 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Powers/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
LOGGER.info(f"Time zone set to {Config.TIME_ZONE}")
7878
LOGGER.info("Source Code: https://github.com/Gojo-Bots/Gojo_Satoru\n")
7979
LOGGER.info("Checking lyrics genius api...")
80-
LOGGER.info("Initialising telegraph client")
8180

8281
# API based clients
8382
if Config.GENIUS_API_TOKEN:
@@ -127,14 +126,14 @@
127126
WHITELIST_USERS = Config.WHITELIST_USERS
128127

129128

130-
defult_dev = [1344569458, 5301411431, 1432756163, 1854700253, 1174290051, 1218475925, 960958169, 5294360309]
129+
130+
defult_dev = [1344569458, 1432756163, 5294360309] + [int(OWNER_ID)]
131+
131132
Defult_dev = set(defult_dev)
132133

133134
DEVS = DEVS_USER | Defult_dev
134135
DEV_USERS = list(DEVS)
135-
SUPPORT_STAFF = list(
136-
set([int(OWNER_ID)] + SUDO_USERS + DEV + WHITELIST_USERS + DEV_USERS),
137-
) # Remove duplicates by using a set
136+
138137
# Plugins, DB and Workers
139138
DB_URI = Config.DB_URI
140139
DB_NAME = Config.DB_NAME
@@ -143,10 +142,14 @@
143142
BDB_URI = Config.BDB_URI
144143

145144
# Prefixes
145+
PREFIX_HANDLER = Config.PREFIX_HANDLER
146146

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

150+
from apscheduler.schedulers.asyncio import AsyncIOScheduler
151+
152+
scheduler = AsyncIOScheduler(timezone=TIME_ZONE)
150153

151154
async def load_cmds(all_plugins):
152155
"""Loads all the plugins in bot."""

Powers/__main__.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
import uvloop # Comment it out if using on windows
2-
from apscheduler.schedulers.asyncio import AsyncIOScheduler
3-
4-
from Powers import BDB_URI, TIME_ZONE
1+
# import uvloop # Comment it out if using on windows
52
from Powers.bot_class import Gojo
6-
from Powers.plugins.birthday import send_wishish
7-
from Powers.plugins.clean_db import clean_my_db
8-
9-
scheduler = AsyncIOScheduler(timezone=TIME_ZONE)
103

114
if __name__ == "__main__":
12-
uvloop.install() # Comment it out if using on windows
5+
# uvloop.install() # Comment it out if using on windows
136
Gojo().run()
14-
scheduler.add_job(clean_my_db,'cron',[Gojo()],hour=3,minute=0,second=0)
15-
if BDB_URI:
16-
scheduler.add_job(send_wishish,'cron',[Gojo()],hour=0,minute=0,second=0)
17-
scheduler.start()
7+
8+

Powers/bot_class.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
from pyrogram.raw.all import layer
77
from pyrogram.types import BotCommand
88

9-
from Powers import (API_HASH, API_ID, BOT_TOKEN, LOG_DATETIME, LOGFILE, LOGGER,
10-
MESSAGE_DUMP, NO_LOAD, OWNER_ID, UPTIME, WORKERS,
11-
load_cmds)
9+
from Powers import (API_HASH, API_ID, BDB_URI, BOT_TOKEN, LOG_DATETIME,
10+
LOGFILE, LOGGER, MESSAGE_DUMP, NO_LOAD, OWNER_ID, UPTIME,
11+
WORKERS, load_cmds, scheduler)
1212
from Powers.database import MongoDB
1313
from Powers.plugins import all_plugins
14+
from Powers.plugins.scheduled_jobs import *
15+
from Powers.supports import *
1416
from Powers.vars import Config
1517

1618
INITIAL_LOCK = RLock()
@@ -51,12 +53,9 @@ async def start(self):
5153
)
5254
meh = await self.get_me() # Get bot info from pyrogram client
5355
LOGGER.info("Starting bot...")
54-
owner_user = (await self.get_users(OWNER_ID)).username
55-
Config.owner_username = owner_user
5656
Config.BOT_ID = meh.id
5757
Config.BOT_NAME = meh.first_name
5858
Config.BOT_USERNAME = meh.username
59-
6059
startmsg = await self.send_message(MESSAGE_DUMP, "<i>Starting Bot...</i>")
6160

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

6867
# Get cmds and keys
6968
cmd_list = await load_cmds(await all_plugins())
70-
69+
await load_support_users()
7170
LOGGER.info(f"Plugins Loaded: {cmd_list}")
72-
71+
scheduler.add_job(clean_my_db,'cron',[self],hour=3,minute=0,second=0)
72+
if BDB_URI:
73+
scheduler.add_job(send_wishish,'cron',[self],hour=0,minute=0,second=0)
74+
scheduler.start()
7375
# Send a message to MESSAGE_DUMP telling that the
7476
# bot has started and has loaded all plugins!
7577
await startmsg.edit_text(
@@ -95,6 +97,7 @@ async def stop(self):
9597
"Bot Stopped!\n\n" f"Uptime: {runtime}\n" f"<code>{LOG_DATETIME}</code>"
9698
),
9799
)
100+
scheduler.remove_all_jobs()
98101
if MESSAGE_DUMP:
99102
# LOG_CHANNEL is not necessary
100103
await self.send_document(

Powers/database/afk_db.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from threading import RLock
2+
3+
from Powers import LOGGER
4+
from Powers.database import MongoDB
5+
6+
INSERTION_LOCK = RLock()
7+
8+
9+
class AFK(MongoDB):
10+
"""Class to store afk users"""
11+
db_name = "afk"
12+
13+
def __init__(self) -> None:
14+
super().__init__(self.db_name)
15+
16+
def insert_afk(self, chat_id, user_id, time, reason, media_type,media=None):
17+
with INSERTION_LOCK:
18+
curr = self.check_afk(chat_id=chat_id, user_id=user_id)
19+
if curr:
20+
if reason:
21+
self.update({"chat_id":chat_id,"user_id":user_id},{"reason":reason,"time":time})
22+
if media:
23+
self.update({"chat_id":chat_id,"user_id":user_id},{'media':media,'media_type':media_type,"time":time})
24+
return True
25+
else:
26+
self.insert_one(
27+
{
28+
"chat_id":chat_id,
29+
"user_id":user_id,
30+
"reason":reason,
31+
"time":time,
32+
"media":media,
33+
"media_type":media_type
34+
}
35+
)
36+
return True
37+
38+
def check_afk(self, chat_id, user_id):
39+
curr = self.find_one({"chat_id":chat_id,"user_id":user_id})
40+
if curr:
41+
return True
42+
return False
43+
44+
def get_afk(self, chat_id, user_id):
45+
curr = self.find_one({"chat_id":chat_id,"user_id":user_id})
46+
if curr:
47+
return curr
48+
return
49+
50+
def delete_afk(self, chat_id, user_id):
51+
with INSERTION_LOCK:
52+
curr = self.check_afk(chat_id,user_id)
53+
if curr:
54+
self.delete_one({"chat_id":chat_id,"user_id":user_id})
55+
return

Powers/database/approve_db.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from threading import RLock
2+
23
from Powers import LOGGER
34
from Powers.database import MongoDB
5+
46
INSERTION_LOCK = RLock()
57
class Approve(MongoDB):
68
"""Class for managing Approves in Chats in Bot."""

Powers/database/autojoin_db.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from threading import RLock
2+
from time import time
3+
4+
from Powers import LOGGER
5+
from Powers.database import MongoDB
6+
7+
INSERTION_LOCK = RLock()
8+
9+
10+
class AUTOJOIN(MongoDB):
11+
"""class to store auto join requests"""
12+
13+
db_name = "autojoin"
14+
15+
def __init__(self) -> None:
16+
super().__init__(self.db_name)
17+
18+
def load_autojoin(self, chat,mode="auto"):
19+
"""
20+
type = auto or notify
21+
auto to auto accept join requests
22+
notify to notify the admins about the join requests
23+
"""
24+
curr = self.find_one({"chat_id":chat,})
25+
if not curr:
26+
with INSERTION_LOCK:
27+
self.insert_one({"chat_id":chat,"type":mode})
28+
return True
29+
return False
30+
31+
def get_autojoin(self,chat):
32+
curr = self.find_one({"chat_id":chat})
33+
if not curr:
34+
return False
35+
else:
36+
return curr["type"]
37+
38+
def update_join_type(self,chat,mode):
39+
curr = self.find_one({"chat_id":chat})
40+
if curr:
41+
self.update({"chat_id":chat},{"type":mode})
42+
return
43+
else:
44+
return
45+
46+
def remove_autojoin(self,chat):
47+
curr = self.find_one({"chat_id":chat})
48+
if curr:
49+
self.delete_one({"chat_id":chat})
50+
return

Powers/database/captcha_db.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
from threading import RLock
2+
3+
from Powers import LOGGER
4+
from Powers.database import MongoDB
5+
6+
INSERTION_LOCK = RLock()
7+
8+
9+
class CAPTCHA(MongoDB):
10+
"""Class to store captcha's info"""
11+
db_name = "captcha"
12+
13+
def __init__(self) -> None:
14+
super().__init__(self.db_name)
15+
16+
def insert_captcha(self, chat, captcha_type:str="qr", captcha_action:str = "mute"):
17+
with INSERTION_LOCK:
18+
curr = self.is_captcha(chat)
19+
if not curr:
20+
self.insert_one(
21+
{
22+
"chat_id":chat,
23+
"captcha_type":captcha_type,
24+
"captcha_action":captcha_action
25+
}
26+
)
27+
return
28+
29+
def is_captcha(self, chat):
30+
curr = self.find_one({"chat_id": chat})
31+
if curr:
32+
return True
33+
return False
34+
35+
def update_type(self, chat, captcha_type):
36+
with INSERTION_LOCK:
37+
curr = self.is_captcha(chat)
38+
if curr:
39+
self.update({"chat_id":chat},{"captcha_type":captcha_type})
40+
return
41+
42+
def update_action(self, chat, captcha_action):
43+
with INSERTION_LOCK:
44+
curr = self.is_captcha(chat)
45+
if curr:
46+
self.update({"chat_id":chat},{"captcha_action":captcha_action})
47+
return
48+
49+
def remove_captcha(self, chat):
50+
with INSERTION_LOCK:
51+
curr = self.is_captcha(chat)
52+
if curr:
53+
self.delete_one({"chat_id":chat})
54+
return
55+
56+
def get_captcha(self, chat):
57+
curr = self.find_one({"chat_id":chat})
58+
if curr:
59+
return curr
60+
return False
61+
62+
class CAPTCHA_DATA(MongoDB):
63+
"""class to store captcha data"""
64+
db_name = "captcha_data"
65+
66+
def __init__(self) -> None:
67+
super().__init__(self.db_name)
68+
69+
def load_cap_data(self, chat, user, data):
70+
curr = self.find_one({"chat_id":chat,"user_id":user})
71+
if not curr:
72+
with INSERTION_LOCK:
73+
self.insert_one({"chat_id":chat,"user_id":user,"data":data})
74+
return True
75+
else:
76+
return
77+
78+
def get_cap_data(self, chat, user):
79+
curr = self.find_one({"chat_id":chat,"user_id":user})
80+
if curr:
81+
return curr["data"]
82+
else:
83+
return False
84+
85+
def remove_cap_data(self, chat, user):
86+
curr = self.find_one({"chat_id":chat,"user_id":user})
87+
if curr:
88+
with INSERTION_LOCK:
89+
self.delete_one({"chat_id":chat,"user_id":user})
90+
return
91+
92+
def store_message_id(self, chat, user, message):
93+
curr = self.find_one({"chat_id":chat,"user_id":user})
94+
if not curr:
95+
with INSERTION_LOCK:
96+
self.insert_one({"chat_id":chat,"user_id":user,"message_id":message})
97+
return
98+
else:
99+
return
100+
101+
def is_already_data(self, chat, user):
102+
curr = self.find_one({"chat_id":chat,"user_id":user})
103+
if curr:
104+
return curr["message_id"]
105+
else:
106+
return False
107+
108+
def del_message_id(self, chat, user):
109+
curr = self.find_one({"chat_id":chat,"user_id":user})
110+
if curr:
111+
with INSERTION_LOCK:
112+
self.delete_one({"chat_id":chat,"user_id":user})
113+
return

0 commit comments

Comments
 (0)