initial commit
This commit is contained in:
		
							
								
								
									
										26
									
								
								bot/app.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								bot/app.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
import discord, asyncio
 | 
			
		||||
import os
 | 
			
		||||
from discord.ext import commands
 | 
			
		||||
from discord import app_commands
 | 
			
		||||
import database.controller
 | 
			
		||||
 | 
			
		||||
intents = discord.Intents.default()
 | 
			
		||||
intents.members = True
 | 
			
		||||
intents.dm_messages = True
 | 
			
		||||
 | 
			
		||||
app = commands.Bot(command_prefix=",", intents=intents)
 | 
			
		||||
app.db = database.controller.Database("database.db")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# load cogs
 | 
			
		||||
async def load_cogs():
 | 
			
		||||
    for filename in os.listdir("bot/commands"):
 | 
			
		||||
        if filename.endswith(".py"):
 | 
			
		||||
            await app.load_extension(f"bot.commands.{filename[:-3]}")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.event
 | 
			
		||||
async def on_ready():
 | 
			
		||||
    print("Running")
 | 
			
		||||
    await load_cogs()
 | 
			
		||||
    await app.tree.sync()
 | 
			
		||||
							
								
								
									
										32
									
								
								bot/commands/SubscribeCommand.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								bot/commands/SubscribeCommand.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
from database.controller import Database
 | 
			
		||||
import discord
 | 
			
		||||
from discord import app_commands
 | 
			
		||||
from discord.ext import commands
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SubscribeCommand(commands.Cog):
 | 
			
		||||
    def __init__(self, app: commands.Bot) -> None:
 | 
			
		||||
        self.app = app
 | 
			
		||||
 | 
			
		||||
    @app_commands.command(
 | 
			
		||||
        name="subscribe", description="Subscribe to BeReal. notifications."
 | 
			
		||||
    )
 | 
			
		||||
    async def subscribe(self, interaction: discord.Interaction) -> None:
 | 
			
		||||
        result = self.app.db.add_subscriber(interaction.user.id)
 | 
			
		||||
        if result:
 | 
			
		||||
            await interaction.response.send_message(
 | 
			
		||||
                ":information_source: You have been subscribed to **BeReal. notifications**\n\
 | 
			
		||||
:arrow_right: You will receive every day notifications whenever it's\
 | 
			
		||||
time to BeReal.\n:warning: You may unsubscribe at any time using `/unsubscribe`.",
 | 
			
		||||
                ephemeral=True,
 | 
			
		||||
            )
 | 
			
		||||
        else:
 | 
			
		||||
            await interaction.response.send_message(
 | 
			
		||||
                ":information_source: You are already subscribed to **BeReal. notifications**\
 | 
			
		||||
\n:warning: You may unsubscribe at any time using `/unsubscribe`.",
 | 
			
		||||
                ephemeral=True,
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def setup(app: commands.Bot) -> None:
 | 
			
		||||
    await app.add_cog(SubscribeCommand(app))
 | 
			
		||||
							
								
								
									
										31
									
								
								bot/commands/UnsubscribeCommand.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								bot/commands/UnsubscribeCommand.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
import discord
 | 
			
		||||
from discord import app_commands
 | 
			
		||||
from discord.ext import commands
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class UnsubscribeCommand(commands.Cog):
 | 
			
		||||
    def __init__(self, app: commands.Bot) -> None:
 | 
			
		||||
        self.app = app
 | 
			
		||||
 | 
			
		||||
    @app_commands.command(
 | 
			
		||||
        name="unsubscribe", description="Unsubscribe to BeReal. notifications."
 | 
			
		||||
    )
 | 
			
		||||
    async def unsubscribe(self, interaction: discord.Interaction) -> None:
 | 
			
		||||
        result = self.app.db.remove_subscriber(interaction.user.id)
 | 
			
		||||
        if result:
 | 
			
		||||
            await interaction.response.send_message(
 | 
			
		||||
                ":information_source: You have been unsubscribed to **BeReal. notifications**\n\
 | 
			
		||||
:arrow_right: You will **no longer receive** every day notifications whenever it's\
 | 
			
		||||
time to BeReal.\n:warning: You may re-subscribe at any time using `/subscribe`.",
 | 
			
		||||
                ephemeral=True,
 | 
			
		||||
            )
 | 
			
		||||
        else:
 | 
			
		||||
            await interaction.response.send_message(
 | 
			
		||||
                ":information_source: You are already not subscribed to **BeReal. notifications**\
 | 
			
		||||
\n:warning: You may subscribe at any time using `/subscribe`.",
 | 
			
		||||
                ephemeral=True,
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def setup(app: commands.Bot) -> None:
 | 
			
		||||
    await app.add_cog(UnsubscribeCommand(app))
 | 
			
		||||
		Reference in New Issue
	
	Block a user