Skip to content

Commit

Permalink
feat: deploy application on push to main branch (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkellyBG authored Feb 20, 2024
1 parent 443c17e commit eb0f03f
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 14 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fly.toml
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DISCORD_TOKEN=insert_bot_token_here
18 changes: 18 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy to Fly

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
14 changes: 14 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Check Formatting

on: [pull_request]

jobs:
check-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
with:
options: "--check --verbose"
src: "."
version: "~= 23.0"
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,9 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Python virtual environment
bin/**
lib64/**
pyvenv.cfg
lib64
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.10
WORKDIR /bot
COPY requirements.txt /bot/
RUN pip install -r requirements.txt
COPY . /bot
CMD python main.py
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TODO: Modify this Procfile to fit your needs
web: gunicorn app:app
10 changes: 7 additions & 3 deletions cogs/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from discord.ext import commands
from discord import app_commands


class Answers(commands.Cog):
def __init__(self, bot):
self.bot = bot
Expand All @@ -13,14 +14,17 @@ def __init__(self, bot):
"God's Kitchen": "what's the opposite of gordon ramsay",
"Librinth": "books idk",
"Susharks in the Wafer": "i'm kinda hungry",
"We Need to Eat": "aaaaaaaaanoodl"
"We Need to Eat": "aaaaaaaaanoodl",
}

@app_commands.command(name="check")
# remember to add a check so that users can only check answers in their respective
# team channels
async def check_answer(self, interaction: discord.Interaction, puzz_name: str, answer: str):
async def check_answer(
self, interaction: discord.Interaction, puzz_name: str, answer: str
):
pass


async def setup(bot: commands.Bot):
await bot.add_cog(Answers(bot))
await bot.add_cog(Answers(bot))
13 changes: 8 additions & 5 deletions cogs/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from discord import app_commands
from discord import Guild


class Team(commands.GroupCog):
def __init__(self, bot):
self.bot = bot
Expand All @@ -16,28 +17,30 @@ async def create_team(self, interaction: discord.Interaction, team_name: str):
# include code to check that the name is not already taken
# will involve a call to the respective sql function


# if name not taken, add check for profanity and such

team_role = await Guild.create_role(guild, name=team_name)
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
team_role: discord.PermissionOverwrite(read_messages=True)
team_role: discord.PermissionOverwrite(read_messages=True),
}
category = await Guild.create_category(guild, team_name, overwrites=overwrites)
await category.create_text_channel(name=team_name)
await category.create_voice_channel(name=team_name)

# give role to user
await user.add_roles(team_role)
await interaction.response.send_message(f"Team \"{team_name}\" created successfully!")
await interaction.response.send_message(
f'Team "{team_name}" created successfully!'
)

@app_commands.command(name="leave")
async def leave_team(self, interaction: discord.Interaction, team_name: str):
# remove team role from user
# if there are no more people in the team, delete the role and channels

pass


async def setup(bot: commands.Bot):
await bot.add_cog(Team(bot))
await bot.add_cog(Team(bot))
7 changes: 7 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# fly.toml app configuration file generated for puzzlehunt-bot on 2024-02-20T18:02:57+11:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'puzzlehunt-bot'
primary_region = 'syd'
16 changes: 11 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import discord
from discord.ext import commands
from src.config import config
import os

TOKEN = ""
Expand All @@ -8,12 +9,14 @@

intents = discord.Intents.all()

bot = commands.Bot(command_prefix='!', help_command=None, intents=intents)
bot = commands.Bot(command_prefix="!", help_command=None, intents=intents)


@bot.event
async def on_ready():
print(f"Connected as {bot.user}.")


# load all available cogs on startup
@bot.command()
@commands.has_role(EXEC_ID)
Expand All @@ -24,36 +27,39 @@ async def startup(ctx: commands.context.Context):
print(f"Loaded {filename}")
await ctx.send(f"Loaded all cogs")


# command to load a cog
@bot.command()
@commands.has_role(EXEC_ID)
async def load(ctx: commands.context.Context, extension):
await bot.load_extension(f"{COGS_DIR}.{extension}")
await ctx.send(f"Loaded {extension} cog")


# command to unload a cog
@bot.command()
@commands.has_role(EXEC_ID)
async def unload(ctx: commands.context.Context, extension):
await bot.unload_extension(f"{COGS_DIR}.{extension}")
await ctx.send(f"Unloaded {extension} cog")


# command to reload a cog
@bot.command()
@commands.has_role(EXEC_ID)
async def reload(ctx: commands.context.Context, extension):
await bot.reload_extension(f"{COGS_DIR}.{extension}")
await ctx.send(f"Reloaded {extension} cog")


@bot.command()
async def sync(ctx: commands.context.Context):
try:
synced = await bot.tree.sync()
bot.tree.copy_global_to(guild=ctx.guild)
synced = await bot.tree.sync(guild=ctx.guild)
await ctx.send(f"Synced {len(synced)} commands.")
except Exception as e:
print(e)

with open(".token", 'r') as t:
TOKEN = t.readline().strip()

bot.run(TOKEN)
bot.run(config["DISCORD_TOKEN"])
12 changes: 11 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
discord
aiohttp==3.9.3
aiosignal==1.3.1
async-timeout==4.0.3
attrs==23.2.0
discord==2.3.2
discord.py==2.3.2
frozenlist==1.4.1
idna==3.6
multidict==6.0.5
python-dotenv==1.0.1
yarl==1.9.4
9 changes: 9 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os
from dotenv import load_dotenv

load_dotenv()

config: dict[str, str] = {
"DISCORD_TOKEN": os.environ["DISCORD_TOKEN"],
"DATABASE_URL": os.environ["DATABASE_URL"],
}

0 comments on commit eb0f03f

Please sign in to comment.