|
import datetime |
|
import sqlite3 |
|
import discord |
|
import os |
|
from discord.ext import commands |
|
from dotenv import load_dotenv |
|
|
|
load_dotenv() |
|
AuthorisedUsersID = os.getenv('BotOwner') |
|
if AuthorisedUsersID is not None: |
|
AuthorisedUsersID = int(AuthorisedUsersID) |
|
|
|
con = sqlite3.connect("AngelMusic.db") |
|
cur = con.cursor() |
|
|
|
# Create a table to store premium guild information |
|
cur.execute('''CREATE TABLE IF NOT EXISTS premium_guilds |
|
(id INTEGER PRIMARY KEY, |
|
guild_id BIGINT, |
|
premium_start TEXT, |
|
premium_end TEXT)''') |
|
con.commit() |
|
|
|
class AddPremium(commands.Cog): |
|
def __init__(self, bot, cur, con): |
|
self.bot = bot |
|
self.cur = cur |
|
self.con = con |
|
|
|
async def cog_check(self, ctx): |
|
if ctx.author.id == AuthorisedUsersID: |
|
return True |
|
else: |
|
embed = discord.Embed( |
|
title="Unauthorized", |
|
description=f"You are not authorized to use this command.", |
|
color=discord.Color.dark_blue(), |
|
timestamp=ctx.message.created_at |
|
) |
|
embed.set_author( |
|
name=self.bot.user.name, |
|
icon_url=self.bot.user.display_avatar.url |
|
) |
|
embed.set_footer(text="Made by NNKtv28") |
|
await ctx.send(embed=embed) |
|
return False |
|
|
|
@commands.command() |
|
async def addpremium(self, ctx, guild_id: int, days: int): |
|
"Add a guild to the premium_guilds table." |
|
|
|
|
|
guild = self.bot.get_guild(guild_id) |
|
if not guild: |
|
embed = discord.Embed( |
|
title= "Add premium Error", |
|
description=f"❌ | Invalid guild ID.", |
|
color=discord.Color.dark_blue(), |
|
timestamp=ctx.message.created_at |
|
) |
|
embed.set_author( |
|
name=self.bot.user.name, |
|
icon_url=self.bot.user.display_avatar.url |
|
) |
|
embed.set_footer(text="Made by NNKtv28") |
|
await ctx.send(embed=embed) |
|
return |
|
|
|
current_time = datetime.datetime.utcnow() |
|
premium_start = current_time.strftime("%Y-%m-%d %H:%M:%S") |
|
premium_end = (current_time + datetime.timedelta(days=days)).strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
# Check if guild already exists in the premium_guilds table |
|
self.cur.execute('SELECT * FROM premium_guilds WHERE guild_id = ?', (guild_id,)) |
|
result = self.cur.fetchone() |
|
|
|
if result: |
|
existing_start = result[2] |
|
existing_end = result[3] |
|
existing_start_time = datetime.datetime.strptime(existing_start, "%Y-%m-%d %H:%M:%S") |
|
existing_end_time = datetime.datetime.strptime(existing_end, "%Y-%m-%d %H:%M:%S") |
|
new_end_time = existing_end_time + datetime.timedelta(days=days) |
|
new_end = new_end_time.strftime("%Y-%m-%d %H:%M:%S") |
|
self.cur.execute('UPDATE premium_guilds SET premium_end = ? WHERE guild_id = ?', (new_end, guild_id)) |
|
self.con.commit() |
|
else: |
|
self.cur.execute('INSERT INTO premium_guilds (guild_id, premium_start, premium_end) VALUES (?, ?, ?)', |
|
(guild_id, premium_start, premium_end)) |
|
self.con.commit() |
|
|
|
embed = discord.Embed( |
|
title= "Added premium", |
|
description=f"✅ | Added {guild.name} to premium guilds list until {new_end_time}.", |
|
color=discord.Color.dark_blue(), |
|
timestamp=ctx.message.created_at |
|
) |
|
embed.set_author( |
|
name=self.bot.user.name, |
|
icon_url=self.bot.user.display_avatar.url |
|
) |
|
embed.set_footer(text="Made by NNKtv28") |
|
await ctx.send(embed=embed) |
|
|
|
async def setup(bot): |
|
await bot.add_cog(AddPremium(bot, cur, con)) |