Compare commits
No commits in common. "9a4ed06d79f231b552106a1c880d30f8ef410a16" and "bc0f71d5bea799762651af8f7befa0d32534b64f" have entirely different histories.
9a4ed06d79
...
bc0f71d5be
4 changed files with 24 additions and 211 deletions
187
.gitignore
vendored
187
.gitignore
vendored
|
@ -1,185 +1,4 @@
|
||||||
# Byte-compiled / optimized / DLL files
|
/venv/*
|
||||||
__pycache__/
|
|
||||||
*.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
|
gacha_game.db
|
||||||
bot/client.py
|
__pycache__/
|
||||||
|
bot/client.py
|
|
@ -1,15 +1,25 @@
|
||||||
import time
|
|
||||||
import misskey
|
import misskey
|
||||||
|
import os
|
||||||
|
import asyncio
|
||||||
from parsing import parse_notification
|
from parsing import parse_notification
|
||||||
from db_utils import get_or_create_user, add_pull, get_config, set_config
|
from db_utils import get_or_create_user, add_pull, get_config, set_config
|
||||||
from client import client_connection
|
from client import client_connection
|
||||||
|
|
||||||
# Initialize the Misskey client
|
# 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()
|
client = client_connection()
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
# Define your whitelist
|
# Define your whitelist
|
||||||
# TODO: move to config
|
whitelisted_instances = []
|
||||||
whitelisted_instances: list[str] = []
|
|
||||||
|
|
||||||
def stream_notifications():
|
def stream_notifications():
|
||||||
print("Starting filtered notification stream...")
|
print("Starting filtered notification stream...")
|
||||||
|
@ -18,9 +28,6 @@ def stream_notifications():
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
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()
|
notifications = client.i_notifications()
|
||||||
|
|
||||||
if notifications:
|
if notifications:
|
||||||
|
|
|
@ -1,26 +1,22 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import random
|
import random
|
||||||
|
|
||||||
# TODO: grab this from a config file instead
|
|
||||||
DB_PATH = "./gacha_game.db" # Adjust if needed
|
DB_PATH = "./gacha_game.db" # Adjust if needed
|
||||||
|
|
||||||
def get_db_connection():
|
def get_db_connection():
|
||||||
'''Creates a connection to the database'''
|
|
||||||
conn = sqlite3.connect(DB_PATH)
|
conn = sqlite3.connect(DB_PATH)
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
def get_or_create_user(username):
|
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 = get_db_connection()
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute('SELECT id FROM users WHERE username = ?', (username,))
|
cur.execute('SELECT * FROM users WHERE username = ?', (username,))
|
||||||
user = cur.fetchone()
|
user = cur.fetchone()
|
||||||
if user:
|
if user:
|
||||||
conn.close()
|
conn.close()
|
||||||
return user
|
return user['id']
|
||||||
|
|
||||||
# New user starts with has_rolled = False
|
# New user starts with has_rolled = False
|
||||||
cur.execute(
|
cur.execute(
|
||||||
|
@ -33,7 +29,6 @@ def get_or_create_user(username):
|
||||||
return user_id
|
return user_id
|
||||||
|
|
||||||
def add_pull(user_id, character_id):
|
def add_pull(user_id, character_id):
|
||||||
'''Creates a pull in the database'''
|
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute('INSERT INTO pulls (user_id, character_id) VALUES (?, ?)', (user_id, character_id))
|
cur.execute('INSERT INTO pulls (user_id, character_id) VALUES (?, ?)', (user_id, character_id))
|
||||||
|
@ -41,7 +36,6 @@ def add_pull(user_id, character_id):
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
def get_config(key):
|
def get_config(key):
|
||||||
'''Reads the value for a specified config key from the db'''
|
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute("SELECT value FROM config WHERE key = ?", (key,))
|
cur.execute("SELECT value FROM config WHERE key = ?", (key,))
|
||||||
|
@ -50,9 +44,8 @@ def get_config(key):
|
||||||
return row[0] if row else None
|
return row[0] if row else None
|
||||||
|
|
||||||
def set_config(key, value):
|
def set_config(key, value):
|
||||||
'''Writes the value for a specified config key to the db'''
|
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute("INSERT OR REPLACE INTO config (key, value) VALUES (?, ?)", (key, value))
|
cur.execute("INSERT OR REPLACE INTO config (key, value) VALUES (?, ?)", (key, value))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
|
@ -3,7 +3,6 @@ from db_utils import get_or_create_user, add_pull, get_db_connection
|
||||||
from add_character import add_character
|
from add_character import add_character
|
||||||
|
|
||||||
def get_character():
|
def get_character():
|
||||||
''' Gets a random character from the database'''
|
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute('SELECT * FROM characters')
|
cur.execute('SELECT * FROM characters')
|
||||||
|
@ -11,25 +10,21 @@ def get_character():
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
if not characters:
|
if not characters:
|
||||||
return None, None, None, None
|
return None, None
|
||||||
|
|
||||||
weights = [c['weight'] for c in characters]
|
weights = [c['weight'] for c in characters]
|
||||||
chosen = random.choices(characters, weights=weights, k=1)[0]
|
chosen = random.choices(characters, weights=weights, k=1)[0]
|
||||||
|
|
||||||
return chosen['id'], chosen['name'], chosen['file_id'], chosen['rarity']
|
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):
|
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":
|
if command == "roll":
|
||||||
user_id = get_or_create_user(full_user)
|
user_id = get_or_create_user(full_user)
|
||||||
character_id, character_name, file_id, rarity = get_character()
|
character_id, character_name, file_id, rarity = get_character()
|
||||||
|
|
||||||
if not character_id:
|
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. 😿")
|
return(f"@{full_user} Uwaaa... something went wrong! No characters found. 😿")
|
||||||
|
|
||||||
add_pull(user_id,character_id)
|
add_pull(user_id,character_id)
|
||||||
|
@ -40,13 +35,12 @@ def gacha_response(command,full_user, arguments,note_obj):
|
||||||
# Example call from bot logic
|
# Example call from bot logic
|
||||||
image_url = note_obj.get("files", [{}])[0].get("url") if note_obj.get("files") else None
|
image_url = note_obj.get("files", [{}])[0].get("url") if note_obj.get("files") else None
|
||||||
if not image_url:
|
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(
|
character_id, file_id = add_character(
|
||||||
name=arguments[0],
|
name=arguments[0],
|
||||||
rarity=int(arguments[1]),
|
rarity=int(arguments[1]),
|
||||||
weight=float(arguments[2]),
|
weight=float(arguments[2]),
|
||||||
image_url=image_url
|
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