Compare commits
No commits in common. "d76a965e7508af5caeb7a1ac660751436384bc73" and "979e15f525eaba9052f4b78c43330ef0e66919a4" have entirely different histories.
d76a965e75
...
979e15f525
7 changed files with 17 additions and 61 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -182,4 +182,3 @@ cython_debug/
|
||||||
|
|
||||||
# Custom stuff
|
# Custom stuff
|
||||||
gacha_game.db
|
gacha_game.db
|
||||||
config.ini
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import time
|
import time
|
||||||
import traceback
|
|
||||||
import misskey
|
import misskey
|
||||||
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
|
||||||
|
@ -69,7 +68,7 @@ def stream_notifications():
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An exception has occured: {e}\n{traceback.format_exc()}")
|
print(f"Error: {e}")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,8 @@
|
||||||
'''Essentials for the bot to function'''
|
# Essential for the bot to function
|
||||||
import configparser
|
INSTANCE = "" # Bots Misskey instance's URL **with schema**
|
||||||
config = configparser.ConfigParser()
|
KEY = "" # API key for the bot
|
||||||
config.read('config.ini')
|
|
||||||
|
|
||||||
# Username for the bot
|
|
||||||
USER = config['application']['BotUser']
|
|
||||||
|
|
||||||
# API key for the bot
|
|
||||||
KEY = config['application']['ApiKey']
|
|
||||||
# Bot's Misskey instance URL
|
|
||||||
INSTANCE = config['application']['InstanceUrl']
|
|
||||||
|
|
||||||
# Extra stuff for control of the bot
|
# Extra stuff for control of the bot
|
||||||
|
ADMINS = [] # Fedi handles in the traditional 'user@domain.tld' style,
|
||||||
# TODO: move this to db
|
# allows these users to use extra admin exclusive commands
|
||||||
# Fedi handles in the traditional 'user@domain.tld' style, allows these users
|
# with the bot
|
||||||
# to use extra admin exclusive commands with the bot'''
|
|
||||||
ADMINS = config['application']['DefaultAdmins']
|
|
||||||
|
|
|
@ -17,10 +17,10 @@ def get_or_create_user(username):
|
||||||
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 id FROM users WHERE username = ?', (username,))
|
||||||
user = cur.fetchone()
|
user = cur.fetchone()[0]
|
||||||
if user:
|
if user:
|
||||||
conn.close()
|
conn.close()
|
||||||
return user[0]
|
return user
|
||||||
|
|
||||||
# New user starts with has_rolled = False
|
# New user starts with has_rolled = False
|
||||||
cur.execute(
|
cur.execute(
|
||||||
|
|
|
@ -18,14 +18,6 @@ def get_character():
|
||||||
|
|
||||||
return chosen['id'], chosen['name'], chosen['file_id'], chosen['rarity']
|
return chosen['id'], chosen['name'], chosen['file_id'], chosen['rarity']
|
||||||
|
|
||||||
def is_float(val):
|
|
||||||
try:
|
|
||||||
float(val)
|
|
||||||
return True
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: See issue #3, separate command parsing from game logic.
|
# 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
|
'''Parses a given command with arguments, processes the game state and
|
||||||
|
@ -42,7 +34,7 @@ def gacha_response(command,full_user, arguments,note_obj):
|
||||||
|
|
||||||
add_pull(user_id,character_id)
|
add_pull(user_id,character_id)
|
||||||
stars = '⭐️' * rarity
|
stars = '⭐️' * rarity
|
||||||
return([f"@{full_user} 🎲 Congrats! You rolled {stars} **{character_name}**\nShe's all yours now~ 💖✨",[file_id]])
|
return([f"@{full_user} 🎲 Congrats! You rolled **{character_name}** she's {stars} stars! She's all yours now~ 💖✨",[file_id]])
|
||||||
|
|
||||||
if command == "create":
|
if command == "create":
|
||||||
# Example call from bot logic
|
# Example call from bot logic
|
||||||
|
@ -50,15 +42,6 @@ def gacha_response(command,full_user, arguments,note_obj):
|
||||||
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."
|
||||||
|
|
||||||
if len(arguments) != 3:
|
|
||||||
return "Please specify the following attributes in order: name, rarity, drop weighting"
|
|
||||||
|
|
||||||
if not (arguments[1].isnumeric() and 1 <= int(arguments[1]) <= 5):
|
|
||||||
return f"Invalid rarity: '{arguments[1]}' must be a number between 1 and 5"
|
|
||||||
|
|
||||||
if not (is_float(arguments[2]) and 0.0 < float(arguments[2]) <= 1.0):
|
|
||||||
return f"Invalid drop weight: '{arguments[2]}' must be a decimal value between 0.0 and 1.0"
|
|
||||||
|
|
||||||
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]),
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import random, re
|
import random, re
|
||||||
import config
|
|
||||||
from gacha_response import gacha_response
|
from gacha_response import gacha_response
|
||||||
|
|
||||||
def parse_notification(notification,client):
|
def parse_notification(notification,client):
|
||||||
|
@ -32,14 +31,15 @@ def parse_notification(notification,client):
|
||||||
|
|
||||||
note = note_text.strip().lower() if note_text else ""
|
note = note_text.strip().lower() if note_text else ""
|
||||||
|
|
||||||
# Check for both short and fully-qualified name mentions
|
# Will want to move bot name to a config file or find a way to derermine
|
||||||
username_variants = [
|
# AP ID at runtime
|
||||||
config.USER,
|
waifumelon_variants = [
|
||||||
f'@{config.USER.split('@')[1]}'
|
"@waifumelon", # simple mention
|
||||||
|
"@waifumelon@mai.waifuism.life", # fully qualified
|
||||||
]
|
]
|
||||||
|
|
||||||
# Make sure the notification text explicitly mentions the bot
|
# Make sure the notification text explicitly mentions the bot
|
||||||
if not any(variant in note for variant in username_variants):
|
if not any(variant in note for variant in waifumelon_variants):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Find command and arguments after the mention
|
# Find command and arguments after the mention
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
; Rename me to config.ini and put your values in here
|
|
||||||
[application]
|
|
||||||
; Full fedi handle of the bot user
|
|
||||||
BotUser = @bot@example.tld
|
|
||||||
|
|
||||||
; API key for the bot
|
|
||||||
; Generate one by going to Settings > API > Generate access token
|
|
||||||
ApiKey = abcdefghijklmnopqrstuvwxyz012345
|
|
||||||
|
|
||||||
; Fully qualified URL of the instance hosting the bot
|
|
||||||
InstanceUrl = http://example.tld
|
|
||||||
|
|
||||||
; Comma separated list of fedi handles for any administrator users
|
|
||||||
DefaultAdmins = ['admin@example.tld']
|
|
Loading…
Add table
Reference in a new issue