-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v 2.2.0
- Loading branch information
Showing
52 changed files
with
2,037 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.