Compare commits
3 commits
bc0f71d5be
...
9a4ed06d79
Author | SHA1 | Date | |
---|---|---|---|
9a4ed06d79 | |||
da0d1742ff | |||
36f0d4a0d1 |
4 changed files with 211 additions and 24 deletions
187
.gitignore
vendored
187
.gitignore
vendored
|
@ -1,4 +1,185 @@
|
|||
/venv/*
|
||||
gacha_game.db
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
bot/client.py
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# UV
|
||||
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
#uv.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
||||
.pdm.toml
|
||||
.pdm-python
|
||||
.pdm-build/
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# 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/
|
||||
|
||||
# Ruff stuff:
|
||||
.ruff_cache/
|
||||
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
# Cursor
|
||||
# Cursor is an AI-powered code editor.`.cursorignore` specifies files/directories to
|
||||
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
||||
# refer to https://docs.cursor.com/context/ignore-files
|
||||
.cursorignore
|
||||
.cursorindexingignore
|
||||
|
||||
# Custom stuff
|
||||
gacha_game.db
|
||||
bot/client.py
|
||||
|
|
|
@ -1,25 +1,15 @@
|
|||
import time
|
||||
import misskey
|
||||
import os
|
||||
import asyncio
|
||||
from parsing import parse_notification
|
||||
from db_utils import get_or_create_user, add_pull, get_config, set_config
|
||||
from client import client_connection
|
||||
|
||||
# Initialize the Misskey client
|
||||
|
||||
# Function to create a note when a user pulls a character in the gacha game
|
||||
|
||||
|
||||
# Set the access token and instance URL (replace with your own values)
|
||||
|
||||
# Initialize the Misskey client
|
||||
|
||||
client = client_connection()
|
||||
|
||||
import time
|
||||
|
||||
# Define your whitelist
|
||||
whitelisted_instances = []
|
||||
# TODO: move to config
|
||||
whitelisted_instances: list[str] = []
|
||||
|
||||
def stream_notifications():
|
||||
print("Starting filtered notification stream...")
|
||||
|
@ -28,6 +18,9 @@ def stream_notifications():
|
|||
|
||||
while True:
|
||||
try:
|
||||
# May be able to mark notifications as read using misskey.py and
|
||||
# filter them out here. This function also takes a since_id we
|
||||
# could use as well
|
||||
notifications = client.i_notifications()
|
||||
|
||||
if notifications:
|
||||
|
|
|
@ -1,22 +1,26 @@
|
|||
import sqlite3
|
||||
import random
|
||||
|
||||
# TODO: grab this from a config file instead
|
||||
DB_PATH = "./gacha_game.db" # Adjust if needed
|
||||
|
||||
def get_db_connection():
|
||||
'''Creates a connection to the database'''
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
def get_or_create_user(username):
|
||||
'''Retrieves an ID for a given user, if the user does not exist, it will be
|
||||
created.'''
|
||||
conn = get_db_connection()
|
||||
conn.row_factory = sqlite3.Row
|
||||
cur = conn.cursor()
|
||||
cur.execute('SELECT * FROM users WHERE username = ?', (username,))
|
||||
cur.execute('SELECT id FROM users WHERE username = ?', (username,))
|
||||
user = cur.fetchone()
|
||||
if user:
|
||||
conn.close()
|
||||
return user['id']
|
||||
return user
|
||||
|
||||
# New user starts with has_rolled = False
|
||||
cur.execute(
|
||||
|
@ -29,6 +33,7 @@ def get_or_create_user(username):
|
|||
return user_id
|
||||
|
||||
def add_pull(user_id, character_id):
|
||||
'''Creates a pull in the database'''
|
||||
conn = get_db_connection()
|
||||
cur = conn.cursor()
|
||||
cur.execute('INSERT INTO pulls (user_id, character_id) VALUES (?, ?)', (user_id, character_id))
|
||||
|
@ -36,6 +41,7 @@ def add_pull(user_id, character_id):
|
|||
conn.close()
|
||||
|
||||
def get_config(key):
|
||||
'''Reads the value for a specified config key from the db'''
|
||||
conn = get_db_connection()
|
||||
cur = conn.cursor()
|
||||
cur.execute("SELECT value FROM config WHERE key = ?", (key,))
|
||||
|
@ -44,8 +50,9 @@ def get_config(key):
|
|||
return row[0] if row else None
|
||||
|
||||
def set_config(key, value):
|
||||
'''Writes the value for a specified config key to the db'''
|
||||
conn = get_db_connection()
|
||||
cur = conn.cursor()
|
||||
cur.execute("INSERT OR REPLACE INTO config (key, value) VALUES (?, ?)", (key, value))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
conn.close()
|
||||
|
|
|
@ -3,6 +3,7 @@ from db_utils import get_or_create_user, add_pull, get_db_connection
|
|||
from add_character import add_character
|
||||
|
||||
def get_character():
|
||||
''' Gets a random character from the database'''
|
||||
conn = get_db_connection()
|
||||
cur = conn.cursor()
|
||||
cur.execute('SELECT * FROM characters')
|
||||
|
@ -10,21 +11,25 @@ def get_character():
|
|||
conn.close()
|
||||
|
||||
if not characters:
|
||||
return None, None
|
||||
return None, None, None, None
|
||||
|
||||
weights = [c['weight'] for c in characters]
|
||||
chosen = random.choices(characters, weights=weights, k=1)[0]
|
||||
|
||||
return chosen['id'], chosen['name'], chosen['file_id'], chosen['rarity']
|
||||
|
||||
|
||||
# TODO: See issue #3, separate command parsing from game logic.
|
||||
def gacha_response(command,full_user, arguments,note_obj):
|
||||
'''Parses a given command with arguments, processes the game state and
|
||||
returns a response'''
|
||||
|
||||
if command == "roll":
|
||||
user_id = get_or_create_user(full_user)
|
||||
character_id, character_name, file_id, rarity = get_character()
|
||||
|
||||
if not character_id:
|
||||
#TODO: Can't have tuples of a single element
|
||||
# Return these as a dict or object instead.
|
||||
return(f"@{full_user} Uwaaa... something went wrong! No characters found. 😿")
|
||||
|
||||
add_pull(user_id,character_id)
|
||||
|
@ -35,12 +40,13 @@ def gacha_response(command,full_user, arguments,note_obj):
|
|||
# Example call from bot logic
|
||||
image_url = note_obj.get("files", [{}])[0].get("url") if note_obj.get("files") else None
|
||||
if not image_url:
|
||||
return("You need an image to create a character, dumbass.")
|
||||
return "You need an image to create a character, dumbass."
|
||||
|
||||
character_id, file_id = add_character(
|
||||
name=arguments[0],
|
||||
rarity=int(arguments[1]),
|
||||
weight=float(arguments[2]),
|
||||
image_url=image_url
|
||||
)
|
||||
return([f"Added {arguments[0]}, ID {character_id}.",[file_id]])
|
||||
)
|
||||
return([f"Added {arguments[0]}, ID {character_id}.",[file_id]])
|
||||
return None
|
||||
|
|
Loading…
Add table
Reference in a new issue