commit
e4cf9f584e
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -347,4 +347,6 @@ ids
|
|||
|
||||
# database
|
||||
matteo.db
|
||||
matteo.db-wal
|
||||
matteo.db-shm
|
||||
/matteo_env/Lib/site-packages/flask_socketio/__init__.py
|
||||
|
|
|
@ -2,12 +2,17 @@
|
|||
import os, json, datetime, re
|
||||
import sqlite3 as sql
|
||||
|
||||
data_dir = "data"
|
||||
|
||||
def create_connection():
|
||||
#create connection, create db if doesn't exist
|
||||
conn = None
|
||||
try:
|
||||
conn = sql.connect("matteo.db")
|
||||
conn = sql.connect(os.path.join(data_dir, "matteo.db"))
|
||||
|
||||
# enable write-ahead log for performance and resilience
|
||||
conn.execute('pragma journal_mode=wal')
|
||||
|
||||
return conn
|
||||
except:
|
||||
print("oops, db connection no work")
|
||||
|
|
11
games.py
11
games.py
|
@ -2,8 +2,13 @@ import json, random, os, math, jsonpickle
|
|||
from enum import Enum
|
||||
import database as db
|
||||
|
||||
data_dir = "data"
|
||||
games_config_file = os.path.join(data_dir, "games_config.json")
|
||||
|
||||
def config():
|
||||
if not os.path.exists("games_config.json"):
|
||||
if not os.path.exists(os.path.dirname(games_config_file)):
|
||||
os.makedirs(os.path.dirname(games_config_file))
|
||||
if not os.path.exists(games_config_file):
|
||||
#generate default config
|
||||
config_dic = {
|
||||
"default_length" : 3,
|
||||
|
@ -16,11 +21,11 @@ def config():
|
|||
"stolen_base_chance_mod" : 1,
|
||||
"stolen_base_success_mod" : 1
|
||||
}
|
||||
with open("games_config.json", "w") as config_file:
|
||||
with open(games_config_file, "w") as config_file:
|
||||
json.dump(config_dic, config_file, indent=4)
|
||||
return config_dic
|
||||
else:
|
||||
with open("games_config.json") as config_file:
|
||||
with open(games_config_file) as config_file:
|
||||
return json.load(config_file)
|
||||
|
||||
def all_weathers():
|
||||
|
|
|
@ -4,6 +4,8 @@ import onomancer as ono
|
|||
from flask import Flask
|
||||
from uuid import uuid4
|
||||
|
||||
data_dir = "data"
|
||||
config_filename = os.path.join(data_dir, "config.json")
|
||||
|
||||
class Command:
|
||||
def isauthorized(self, user):
|
||||
|
@ -605,7 +607,9 @@ thread1 = threading.Thread(target=main_controller.update_loop)
|
|||
thread1.start()
|
||||
|
||||
def config():
|
||||
if not os.path.exists("config.json"):
|
||||
if not os.path.exists(os.path.dirname(config_filename)):
|
||||
os.makedirs(os.path.dirname(config_filename))
|
||||
if not os.path.exists(config_filename):
|
||||
#generate default config
|
||||
config_dic = {
|
||||
"token" : "",
|
||||
|
@ -617,12 +621,12 @@ def config():
|
|||
"soulscream channel id" : 0,
|
||||
"game_freeze" : 0
|
||||
}
|
||||
with open("config.json", "w") as config_file:
|
||||
with open(config_filename, "w") as config_file:
|
||||
json.dump(config_dic, config_file, indent=4)
|
||||
print("please fill in bot token and any bot admin discord ids to the new config.json file!")
|
||||
quit()
|
||||
else:
|
||||
with open("config.json") as config_file:
|
||||
with open(config_filename) as config_file:
|
||||
return json.load(config_file)
|
||||
|
||||
@client.event
|
||||
|
|
Loading…
Reference in New Issue
Block a user