Skip to content

Commit

Permalink
Merge pull request #2 from PYCONDE/dr-pycon-pydata-changes
Browse files Browse the repository at this point in the history
pycon pydata changes
  • Loading branch information
theopinard authored Mar 18, 2024
2 parents 6902628 + c1e6a1b commit d3bbcb1
Show file tree
Hide file tree
Showing 11 changed files with 476 additions and 179 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/deploy_pydata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy to server

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Deploy to some Server
uses: easingthemes/ssh-deploy@v4
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY_DISCORD }}
SOURCE: "."
REMOTE_HOST: "136.243.153.146"
REMOTE_USER: "root"
TARGET: "/home/discord/"
EXCLUDE: "/dist/, /node_modules/"

SCRIPT_BEFORE: |
whoami
ls -al
SCRIPT_AFTER: |
echo $RSYNC_STDOUT
cd /root/discord
docker compose down
docker compose up --detach --build
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.4
17 changes: 10 additions & 7 deletions EuroPythonBot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

import configuration
from cogs.ping import Ping
from cogs.registration import Registration
from helpers.pretix_connector import PretixOrder
# from cogs.registration import Registration
from cogs.registration_pydata import RegistrationPyData
# from helpers.pretix_connector import PretixOrder
from helpers.tito_connector import TitoOrder

load_dotenv(Path(__file__).resolve().parent.parent / ".secrets")
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
Expand Down Expand Up @@ -45,7 +47,7 @@ async def load_extension(self, name: str, *, package: str | None = None) -> None

def _setup_logging() -> None:
"""Set up a basic logging configuration."""
config = configuration.Config()
config = configuration.Config(testing=True)

# Create a stream handler that logs to stdout (12-factor app)
stream_handler = logging.StreamHandler(stream=sys.stdout)
Expand Down Expand Up @@ -74,15 +76,16 @@ async def main():
_setup_logging()
async with bot:
await bot.add_cog(Ping(bot))
await bot.add_cog(Registration(bot))
await bot.load_extension("extensions.programme_notifications")
await bot.load_extension("extensions.organisers")
await bot.add_cog(RegistrationPyData(bot))
# await bot.load_extension("extensions.programme_notifications")
# await bot.load_extension("extensions.organisers")
await bot.start(DISCORD_BOT_TOKEN)


if __name__ == "__main__":
bot = Bot()
orders = PretixOrder()
# orders = PretixOrder()
orders = TitoOrder()
try:
asyncio.run(main())
except KeyboardInterrupt:
Expand Down
104 changes: 67 additions & 37 deletions EuroPythonBot/cogs/registration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import logging

import discord
Expand All @@ -6,10 +8,13 @@
from configuration import Config
from error import AlreadyRegisteredError, NotFoundError
from helpers.channel_logging import log_to_channel
from helpers.pretix_connector import PretixOrder
# from helpers.pretix_connector import PretixOrder
from helpers.tito_connector import TitoOrder

config = Config()
order_ins = PretixOrder()
order_ins = TitoOrder() # PretixOrder()

CHANGE_NICKNAME = True

EMOJI_POINT = "\N{WHITE LEFT POINTING BACKHAND INDEX}"
ZERO_WIDTH_SPACE = "\N{ZERO WIDTH SPACE}"
Expand All @@ -19,18 +24,26 @@


class RegistrationButton(discord.ui.Button["Registration"]):
def __init__(self, x: int, y: int, label: str, style: discord.ButtonStyle):
def __init__(
self,
registration_form: RegistrationForm,
x: int = 0,
y: int = 0,
label: str = f"Register here {EMOJI_POINT}",
style: discord.ButtonStyle = discord.ButtonStyle.green,
):
super().__init__(style=discord.ButtonStyle.secondary, label=ZERO_WIDTH_SPACE, row=y)
self.x = x
self.y = y
self.label = label
self.style = style
self.registration_form = registration_form

async def callback(self, interaction: discord.Interaction) -> None:
assert self.view is not None

# Launch the modal form
await interaction.response.send_modal(RegistrationForm())
await interaction.response.send_modal(self.registration_form())


class RegistrationForm(discord.ui.Modal, title="Europython 2023 Registration"):
Expand All @@ -48,7 +61,7 @@ class RegistrationForm(discord.ui.Modal, title="Europython 2023 Registration"):
min_length=3,
max_length=50,
style=discord.TextStyle.short,
placeholder="Your Full Name as printed on your ticket/badge",
placeholder="Your full name as printed on your ticket/badge",
)

async def on_submit(self, interaction: discord.Interaction) -> None:
Expand All @@ -62,23 +75,38 @@ async def on_submit(self, interaction: discord.Interaction) -> None:
for role in roles:
role = discord.utils.get(interaction.guild.roles, id=role)
await interaction.user.add_roles(role)
nickname = self.name.value[:32] # Limit to the max length
await interaction.user.edit(nick=nickname)
changed_nickname = True
if CHANGE_NICKNAME:
try:
# TODO(dan): change nickname not working, because no admin permission?
nickname = self.name.value[:32] # Limit to the max length
await interaction.user.edit(nick=nickname)
except discord.errors.Forbidden as ex:
msg = f"Changing nickname for {self.name} did not work: {ex}"
_logger.error(msg)
await log_to_channel(
channel=interaction.client.get_channel(config.REG_LOG_CHANNEL_ID),
interaction=interaction,
error=ex,
)
changed_nickname = False
await log_to_channel(
channel=interaction.client.get_channel(config.REG_LOG_CHANNEL_ID),
interaction=interaction,
name=self.name.value,
order=self.order.value,
roles=roles,
)
await interaction.response.send_message(
f"Thank you {self.name.value}, you are now registered!\n\nAlso, your nickname was"
f"changed to the name you used to register your ticket. This is also the name that"
f" would be on your conference badge, which means that your nickname can be your"
f"'virtual conference badge'.",
ephemeral=True,
delete_after=20,
msg = f"Thank you {self.name.value}, you are now registered!"

if CHANGE_NICKNAME and changed_nickname:
msg += (
"\n\nAlso, your nickname was changed to the name you used to register your ticket. "
"This is also the name that would be on your conference badge, which means that your nickname can be "
"your 'virtual conference badge'."
)

await interaction.response.send_message(msg, ephemeral=True, delete_after=20)

async def on_error(self, interaction: discord.Interaction, error: Exception) -> None:
# Make sure we know what the error actually is
Expand All @@ -101,19 +129,36 @@ async def on_error(self, interaction: discord.Interaction, error: Exception) ->


class RegistrationView(discord.ui.View):
def __init__(self):
def __init__(
self,
registration_button: RegistrationButton = RegistrationButton,
registration_form: RegistrationForm = RegistrationForm,
):
# We don't timeout to have a persistent View
super().__init__(timeout=None)
self.value = None
self.add_item(
RegistrationButton(0, 0, f"Register here {EMOJI_POINT}", discord.ButtonStyle.green)
)
self.add_item(registration_button(registration_form=registration_form))


class Registration(commands.Cog):
def __init__(self, bot):
def __init__(self, bot, registration_view: RegistrationView = RegistrationView):
self.bot = bot
self.guild = None
self._title = "Welcome to EuroPython 2023 on Discord! 🎉🐍"
self._desc = (
"Follow these steps to complete your registration:\n\n"
f'1️⃣ Click on the green "Register Here {EMOJI_POINT}" button.\n\n'
'2️⃣ Fill in the "Order" (found by clicking the order URL in your confirmation '
'email from [email protected] with the Subject: Your order: XXXX) and "Full Name" '
"(as printed on your ticket/badge).\n\n"
'3️⃣ Click "Submit". We\'ll verify your ticket and give you your role based on '
"your ticket type.\n\n"
"Experiencing trouble? Ask for help in the registration-help channel or from a "
"volunteer in yellow t-shirt at the conference.\n\n"
"See you on the server! 🐍💻🎉"
)
self.registration_view = registration_view

_logger.info("Cog 'Registration' has been initialized")

@commands.Cog.listener()
Expand All @@ -127,25 +172,10 @@ async def on_ready(self):
await order_ins.fetch_data()
order_ins.load_registered()

_title = "Welcome to EuroPython 2023 on Discord! 🎉🐍"
_desc = (
"Follow these steps to complete your registration:\n\n"
f'1️⃣ Click on the green "Register Here {EMOJI_POINT}" button.\n\n'
'2️⃣ Fill in the "Order" (found by clicking the order URL in your confirmation '
'email from [email protected] with the Subject: Your order: XXXX) and "Full Name" '
"(as printed on your ticket/badge).\n\n"
'3️⃣ Click "Submit". We\'ll verify your ticket and give you your role based on '
"your ticket type.\n\n"
"Experiencing trouble? Ask for help in the registration-help channel or from a "
"volunteer in yellow t-shirt at the conference.\n\n"
"See you on the server! 🐍💻🎉"
)

view = RegistrationView()
embed = discord.Embed(
title=_title,
description=_desc,
title=self._title,
description=self._desc,
colour=0xFF8331,
)

await reg_channel.send(embed=embed, view=view)
await reg_channel.send(embed=embed, view=self.registration_view())
53 changes: 53 additions & 0 deletions EuroPythonBot/cogs/registration_pydata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# import logging

import discord
from discord.ext import commands

# from configuration import Config
# from error import AlreadyRegisteredError, NotFoundError
# from helpers.channel_logging import log_to_channel
# from helpers.tito_connector import TitoOrder
from cogs.registration import Registration, RegistrationButton, RegistrationForm, RegistrationView

# config = Config()
# order_ins = TitoOrder()

# CHANGE_NICKNAME = False

EMOJI_POINT = "\N{WHITE LEFT POINTING BACKHAND INDEX}"

# _logger = logging.getLogger(f"bot.{__name__}")


# TODO(dan): make pydata subclass with changes

class RegistrationButtonPyData(RegistrationButton):
def __init__(self, registration_form: RegistrationForm,):
super().__init__(registration_form=RegistrationFormPyData)

class RegistrationFormPyData(RegistrationForm):
def __init__(self):
super().__init__(title="PyConDE/PyData Berlin 2024 Registration")


class RegistrationViewPyData(RegistrationView):
def __init__(self):
super().__init__(registration_button=RegistrationButtonPyData, registration_form=RegistrationFormPyData)

class RegistrationPyData(Registration, commands.Cog):
def __init__(self, bot):
super().__init__(bot, registration_view=RegistrationViewPyData)
self._title = _title = "Welcome to PyConDE / PyData Berlin 2024 on Discord! 🎉🐍"
# TODO(dan): update text
self._desc = (
"Follow these steps to complete your registration:\n\n"
f'1️⃣ Click on the green "Register Here {EMOJI_POINT}" button.\n\n'
'2️⃣ Fill in the "Order" (found by clicking the order URL in your confirmation '
'email from [email protected] with the Subject: Your order: XXXX) and "Full Name" '
"(as printed on your ticket/badge).\n\n"
'3️⃣ Click "Submit". We\'ll verify your ticket and give you your role based on '
"your ticket type.\n\n"
"Experiencing trouble? Ask for help in the registration-help channel or from a "
"volunteer in yellow t-shirt at the conference.\n\n"
"See you on the server! 🐍💻🎉"
)
Loading

0 comments on commit d3bbcb1

Please sign in to comment.