Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/add content intent #16

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Set up Python 3.12
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -36,7 +36,7 @@ jobs:
run: |
pytest --cov --cov-report=html --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.0.0
uses: codecov/codecov-action@v3.1.4
with:
file: out/report/coverage.xml
env_vars: OS,PYTHON
Expand Down
2 changes: 1 addition & 1 deletion app.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
runtime: python38
runtime: python312
entrypoint: python -m roll_witch.main
instance_class: F1
automatic_scaling:
Expand Down
5 changes: 4 additions & 1 deletion roll_witch/dice_bot/event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

class EventListenerClient(discord.Client):
def __init__(self):
intents = discord.Intents(messages=True)
intents: discord.Intents = discord.Intents(
messages=True, guilds=True, message_content=True
)
super().__init__(intents=intents)

async def on_ready(self):
Expand All @@ -20,6 +22,7 @@ async def on_message(self, message):
return
try:
command, roll_string = get_command(message_content=message.content)
print(f"Command {command}")
if command:
response = command.execute(
roll_string=roll_string,
Expand Down
2 changes: 1 addition & 1 deletion roll_witch/rolling/command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"!r-b": basic,
"!roll": token,
"!r": token,
"!sr": shadow_run
"!sr": shadow_run,
}


Expand Down
8 changes: 2 additions & 6 deletions roll_witch/rolling/command/shadow_run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from roll_witch.rolling.input import get_token_parser
from roll_witch.rolling.output import OperationOutputWriter
from roll_witch.rolling.roller import RollResult, RollSpec
from roll_witch.rolling.roller import (
StandardRoller
)
from roll_witch.rolling.roller import StandardRoller
from roll_witch.rolling.roller.operation_result import OperationResult


Expand Down Expand Up @@ -34,7 +32,5 @@ def get_spec(roll_string):
parser = get_token_parser()
roll_spec = parser.parse(roll_string)
if not roll_spec.target_number:
roll_spec.add_part(
RollSpec(target_number=5, operation=None)
)
roll_spec.add_part(RollSpec(target_number=5, operation=None))
return roll_spec
8 changes: 7 additions & 1 deletion roll_witch/rolling/roller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
from .spec import RollSpec
from .operation_result import OperationResult

__all__ = ["StandardRoller", "TargetedRoller", "RollResult", "OperationResult", "RollSpec"]
__all__ = [
"StandardRoller",
"TargetedRoller",
"RollResult",
"OperationResult",
"RollSpec",
]
38 changes: 31 additions & 7 deletions roll_witch/web_app/roller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,41 @@
async def roll(request: Request):
data = await request.post()
try:
bot_operation = command.get_command(
message_content=data["roll_operation"]
)
roll_operation = data["roll_operation"]
if not (roll_operation.startswith("!r")):
roll_operation = f"!r {roll_operation}"

bot_operation, roll_string = command.get_command(message_content=roll_operation)
print(f"Roll Request: {roll_string}")
if bot_operation:
operation_output = bot_operation.execute()
return {"output": operation_output}
operation_output = bot_operation.execute(
roll_string=roll_string,
user="",
)
print(f"Output: {operation_output}")
return {
"output": {
"roll_request": roll_string,
"roll_result": operation_output,
}
}
except ValueError:
return {"output": " Invalid Command"}
return {
"output": {
"error": "Invalid Command",
"roll_request": data["roll_operation"],
"roll_result": "Error",
}
}
except Exception as e:
if hasattr(e, "message"):
msg = e.message
else:
msg = str(e)
return {"output": f"I ain't Dead \n {msg}"}
return {
"output": {
"error": msg,
"roll_request": data["roll_operation"],
"roll_result": "Error",
}
}
9 changes: 3 additions & 6 deletions roll_witch/web_app/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
import os


@aiohttp_jinja2.template("index.jinja2")
async def handle(request):
return {"output": None}


@aiohttp_jinja2.template("roller.jinja2")
async def handle_roller(request):
return {"output": None}
Expand All @@ -24,12 +19,14 @@ async def start_app():

dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, "templates")
staticfiles = os.path.join(dirname, "static")
aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader(filename))

app.router.add_get("/", handle)
app.router.add_get("/", handle_roller)
app.router.add_post("/roll", roller.roll)
app.router.add_get("/roll", handle_roller)
app.router.add_get("/_ah/warmup", warmup)
app.router.add_static("/static", staticfiles)
runner = web.AppRunner(app)
await runner.setup()

Expand Down
173 changes: 173 additions & 0 deletions roll_witch/web_app/static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@

body {
font-family: sans-serif; /* Readable font for body text */
margin: 40px; /* Adds visual space around content */
}

header {
text-align: center; /* Centers the heading */
margin-bottom: 40px; /* Adds spacing below the header */
}

h1 {
font-size: 24px; /* Appropriate size for the main heading */
}

p {
margin-bottom: 10px; /* Adds spacing between paragraphs */
}

.error {
color: red; /* Visually distinguishes error messages */
}

form {
display: flex; /* Arranges form elements horizontally */
flex-direction: column; /* Stacks elements vertically */
align-items: center; /* Aligns elements centrally */
}

label {
margin-bottom: 5px; /* Adds spacing between label and input */
}

input[type="text"] {
padding: 10px; /* Adds padding to input field */
border: 1px solid #ccc; /* Creates a visible border */
border-radius: 5px; /* Softens corners */
margin-bottom: 10px; /* Adds spacing below input */
}

button[type="submit"] {
background-color: #4CAF50; /* Green background for visual emphasis */
color: white; /* White text for contrast */
padding: 10px 20px; /* Adjusts button size */
border: none; /* Removes default border */
border-radius: 5px; /* Softens corners */
cursor: pointer; /* Indicates clickability */
}

main section {
display: flex; /* Arranges main elements horizontally */
flex-direction: column; /* Stacks elements vertically */
align-items: left; /* Aligns elements centrally */
}

aside {
text-align: center; /* Center the inline-block article */
width:20%; /* Set a width for the article */
}

main {
display: flex;
justify-content: center;
width:100%;
}
aside img {
width: 100%;
}

article {
display: inline-block; /* Shrink to fit content */
/* Optional adjustments: */
max-width: 600px; /* Set a maximum width */
padding: 20px; /* Add padding around content */
}

:root {
--charcoal: #2C3333;
--teal: #53A3BE;
--gray: #8F8F8F;
}

/* Body and Background */

body {
background-color: var(--charcoal);
color: var(--gray);
font-family: sans-serif;
}

/* Headings and Text */

h1, h2, h3 {
color: var(--gray);
font-weight: 400;
margin: 1rem 0;
}

p {
line-height: 1.5;
margin-bottom: 1rem;
}

a {
color: var(--teal);
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* Components and Elements */

.article {
background-color: rgba(var(--charcoal), 0.9);
padding: 1rem;
border-radius: 5px;
margin-bottom: 1rem;
}

.form {
display: flex;
flex-direction: column;
gap: 0.5rem;
}

.form label {
color: var(--gray);
margin-bottom: 0.5rem;
}

.form input,
.form button {
background-color: rgba(var(--charcoal), 0.8);
border: 1px solid var(--gray);
border-radius: 5px;
padding: 0.5rem 1rem;
color: var(--gray);
}

.form button {
cursor: pointer;
color: var(--teal);
background-color: var(--teal);
border-color: var(--teal);
transition: color 0.2s ease-in-out, background-color 0.2s ease-in-out;
}

.form button:hover {
color: white;
background-color: rgba(var(--teal), 0.8);
}

/* Additional Enhancements */

.error {
color: red;
font-weight: bold;
}

.highlight {
color: var(--teal);
font-weight: bold;
}

/* Responsive Design */

@media only screen and (min-width: 768px) {
.article {
width: 60%;
}
}
Binary file added roll_witch/web_app/static/witch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions roll_witch/web_app/templates/index.jinja2

This file was deleted.

Loading
Loading