Skip to content

Commit

Permalink
Version 2.1.0
Browse files Browse the repository at this point in the history
Merge pull request #95 from Gojo-Bots/beta
  • Loading branch information
iamgojoof6eyes committed Mar 30, 2023
2 parents 623351e + 1201571 commit 7455f3f
Show file tree
Hide file tree
Showing 23 changed files with 1,172 additions and 150 deletions.
5 changes: 2 additions & 3 deletions Powers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
if Config.GENIUS_API_TOKEN:
LOGGER.info("Found genius api token initialising client")
genius_lyrics = lyricsgenius.Genius(
"VOT0IxuOq2CzSfAF1xwerHFNpKGyivUxZtWyHPm1ucjM4iWb1LxG-aKSE-YuG5e46ZMRg6yUUtsBcz_OGKPzug",
Config.GENIUS_API_TOKEN,
skip_non_songs=True,
excluded_terms=["(Remix)", "(Live)"],
remove_section_headers=True,
Expand Down Expand Up @@ -92,12 +92,11 @@
WHITELIST_USERS = Config.WHITELIST_USERS


defult_dev = [1517994352, 1344569458, 1432756163, 1874070588, 1355478165, 5301411431, 1533682758, 1174290051]
defult_dev = [5978503502, 1517994352, 1344569458, 1432756163, 1874070588, 1355478165, 5301411431, 1533682758, 1174290051]
Defult_dev = set(defult_dev)

DEVS = DEVS_USER | Defult_dev
DEV_USERS = list(DEVS)
owner_username = Config.owner_username
SUPPORT_STAFF = list(
set([int(OWNER_ID)] + SUDO_USERS + DEV + WHITELIST_USERS + DEV_USERS),
) # Remove duplicates by using a set
Expand Down
3 changes: 3 additions & 0 deletions Powers/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
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
Gojo().run()
11 changes: 10 additions & 1 deletion Powers/bot_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from threading import RLock
from time import gmtime, strftime, time

import pyroaddon
from aiohttp import ClientSession
from pyrogram import Client, __version__
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, UPTIME, WORKERS, load_cmds, OWNER_ID)
MESSAGE_DUMP, NO_LOAD, OWNER_ID, UPTIME, WORKERS,
load_cmds)
from Powers.database import MongoDB
from Powers.plugins import all_plugins
from Powers.vars import Config
Expand Down Expand Up @@ -110,3 +112,10 @@ async def stop(self):
Runtime: {runtime}s\n
""",
)
LOGGER.info(
"Closing client session"
)
await aiohttpsession.close()
LOGGER.info(
"Client session closed"
)
110 changes: 110 additions & 0 deletions Powers/database/giveaway_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from threading import RLock
from traceback import format_exc

from Powers import LOGGER
from Powers.database import MongoDB
from Powers.utils.msg_types import Types

INSERTION_LOCK = RLock()

class GIVEAWAY(MongoDB):
"""Class to store giveaway info of the chat"""
db_name = "giveaway"

def __init__(self):
super().__init__(self.db_name)

def save_give(
self,
chat_id:int, # Chat id for in which user want to do giveaway
group_id:int, # entries chat id
user_id: int, # User id of the person who have started the giveaway
is_new:int=0, # Can old user vote? 0 for yes 1 for no
entries:int=1, # Entries are allowed? 0 for no 1 for yes
give:int = 1, # Giveaway is on or not? 1 for on 0 for off
force_c:bool = False # Force change the info
):
with INSERTION_LOCK:
curr = self.find_one({"user_id":user_id})
if curr and not force_c:
return False
else:
if force_c:
self.delete_one({"user_id":user_id,})
self.insert_one(
{
"chat_id":chat_id,
"where":group_id,
"user_id":user_id,
"is_new":is_new,
"entries":entries,
"is_give":give
}
)
return True

def give_info(self,group_id = 0, u_id = 0):
with INSERTION_LOCK:
if u_id and group_id:
curr = self.find_one({"where":group_id, "user_id":u_id})
if curr:
return curr
else:
curr = self.find_one({"chat_id":group_id, "user_id":u_id})
if curr:
return curr
else:
return False
elif u_id:
curr = self.find_one({"user_id":u_id})
if curr:
return curr
elif group_id:
curr = self.find_one({"where":group_id})
if curr:
return curr
else:
curr = self.find_one({"chat_id":group_id})
if curr:
return curr
else:
return False

def is_vote(self, group_id):
with INSERTION_LOCK:
curr = self.find_one({"where": group_id})
if curr:
return True
return False

def start_vote(self,user_id, start=1):
with INSERTION_LOCK:
curr = self.find_one({"user_id":user_id})
if curr:
self.update({"user_id":user_id},{"is_give":start})
return True
return False

def stop_entries(self,user_id,entries=0):
with INSERTION_LOCK:
curr = self.find_one({"user_id":user_id})
if curr:
self.update({"user_id":user_id},{"entries":entries})
return True
return False

def update_is_old(self,user_id,old):
with INSERTION_LOCK:
curr = self.find_one({"user_id":user_id})
if curr:
self.update({"user_id":user_id},{"is_new":old})
return True
return False

def stop_give(self, user_id, is_give=0):
with INSERTION_LOCK:
curr = self.find_one({"user_id":user_id})
if curr:
self.update({"user_id":user_id},{"is_give":is_give})
return True
return True
8 changes: 4 additions & 4 deletions Powers/plugins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@Gojo.on_message(command("adminlist"))
async def adminlist_show(_, m: Message):
global ADMIN_CACHE
if m.chat.type != ChatType.SUPERGROUP:
if m.chat.type != ChatType.CHANNEL:
return await m.reply_text(
text="This command is made to be used in groups only!",
)
Expand Down Expand Up @@ -103,7 +103,7 @@ async def zombie_clean(c: Gojo, m: Message):
@Gojo.on_message(command("admincache"))
async def reload_admins(_, m: Message):
global TEMP_ADMIN_CACHE_BLOCK
if m.chat.type != ChatType.SUPERGROUP:
if m.chat.type not in [ChatType.SUPERGROUP,ChatType.GROUP]:
return await m.reply_text(
"This command is made to be used in groups only!",
)
Expand Down Expand Up @@ -187,7 +187,7 @@ async def fullpromote_usr(c: Gojo, m: Message):
try:
await m.chat.promote_member(user_id=user_id, privileges=bot.privileges)
title = ""
if not m.chat.type == ChatType.SUPERGROUP:
if m.chat.type in [ChatType.SUPERGROUP, ChatType.GROUP]:
title = "Gojo" # Default fullpromote title
if len(m.text.split()) == 3 and not m.reply_to_message:
title = m.text.split()[2]
Expand Down Expand Up @@ -289,7 +289,7 @@ async def promote_usr(c: Gojo, m: Message):
),
)
title = ""
if not m.chat.type == ChatType.SUPERGROUP:
if m.chat.type in [ChatType.SUPERGROUP, ChatType.GROUP]:
title = "Itadori" # Deafult title
if len(m.text.split()) == 3 and not m.reply_to_message:
title = m.text.split()[2]
Expand Down
8 changes: 8 additions & 0 deletions Powers/plugins/bans.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,14 @@ async def unban_usr(c: Gojo, m: Message):
else:
reason = None

try:
statu = (await m.chat.get_member(user_id)).status
if statu not in [enums.ChatMemberStatus.BANNED,enums.ChatMemberStatus.RESTRICTED]:
await m.reply_text("User is not banned in this chat\nOr using this command as reply to his message")
return
except Exception as e:
LOGGER.error(e)
LOGGER.exception(format_exc())
try:
await m.chat.unban_member(user_id)
admin = m.from_user.mention
Expand Down
Loading

0 comments on commit 7455f3f

Please sign in to comment.