mirror of
https://github.com/Sheldan/Sissi.git
synced 2026-01-26 19:21:43 +00:00
[SIS-xxx] adding rendering of current Debra donation information
updating for Debra 2023 campaign adding internal rest api for debra information adding a debra button to receive information
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
from sqlalchemy.sql import text
|
||||
|
||||
def import_commands(server_id, commands, connection):
|
||||
user_ids = [command.author_id for command in commands]
|
||||
create_users(server_id, user_ids, connection)
|
||||
command_id = 2
|
||||
for command in commands:
|
||||
statement = text("""INSERT INTO custom_command(server_id, id, creator_user_in_server_id, additional_message, name)
|
||||
VALUES(:server_id, :id,
|
||||
(select user_in_server_id from user_in_server where user_id = :author_id and server_id = :server_id),
|
||||
:additional_message, :name)""")
|
||||
connection.execute(statement,
|
||||
{'server_id': server_id, 'author_id': command.author_id,
|
||||
'name': command.command, 'additional_message': command.response,
|
||||
'id': command_id})
|
||||
command_id += 1
|
||||
print(f'Creating command for {command.command}')
|
||||
|
||||
|
||||
def create_users(server_id: int, user_ids, con):
|
||||
created_users = {}
|
||||
for user_id in user_ids:
|
||||
if not does_user_exist(user_id, con) and user_id not in created_users:
|
||||
create_user(user_id, con)
|
||||
create_user_in_server(user_id, server_id, con)
|
||||
created_users[user_id] = 1
|
||||
|
||||
|
||||
def does_user_exist(user_id, con):
|
||||
statement = text("""SELECT count(1) FROM auser where id = :id""")
|
||||
return con.execute(statement, {'id': user_id}).fetchone()[0] == 1
|
||||
|
||||
|
||||
def create_user(user_id, con):
|
||||
statement = text("""INSERT INTO auser(id) VALUES(:id)""")
|
||||
print(f'Creating user {user_id}')
|
||||
con.execute(statement, {'id': user_id})
|
||||
|
||||
|
||||
def create_user_in_server(user_id, server_id, con):
|
||||
statement = text("""INSERT INTO user_in_server(server_id, user_id) VALUES(:server_id, :user_id) returning user_in_server_id""")
|
||||
return con.execute(statement, {'user_id': user_id, 'server_id': server_id}).fetchone()[0]
|
||||
5
python/tools/migrations/custom-command-migration/dto.py
Normal file
5
python/tools/migrations/custom-command-migration/dto.py
Normal file
@@ -0,0 +1,5 @@
|
||||
class LegacyCommand:
|
||||
command = ''
|
||||
response = ''
|
||||
author_id = 0
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import json
|
||||
|
||||
from dto import LegacyCommand
|
||||
|
||||
|
||||
def load_all_commands():
|
||||
with open('settings.json') as warnings:
|
||||
lines = warnings.read()
|
||||
command_obj = json.loads(lines)
|
||||
custom_commands = command_obj['414589031223512']['GUILD']['297910194841583616']['commands']
|
||||
all_command_dtos = []
|
||||
for command in custom_commands:
|
||||
custom_command = custom_commands[command]
|
||||
if custom_command is not None and 'response' in custom_command:
|
||||
if len(custom_command['response']) > 2048 or isinstance(custom_command['response'], list):
|
||||
continue
|
||||
command_dto = LegacyCommand()
|
||||
command_dto.command = command
|
||||
command_dto.author_id = custom_command['author']['id']
|
||||
command_dto.response = custom_command['response']
|
||||
all_command_dtos.append(command_dto)
|
||||
print(f'loaded {len(all_command_dtos)} commands.')
|
||||
return all_command_dtos
|
||||
|
||||
20
python/tools/migrations/custom-command-migration/main.py
Normal file
20
python/tools/migrations/custom-command-migration/main.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
import sqlalchemy as db
|
||||
|
||||
from legacy_loader import load_all_commands
|
||||
from command_importer import import_commands
|
||||
|
||||
server_id = os.getenv('SERVER_ID')
|
||||
|
||||
all_warnings = load_all_commands()
|
||||
db_host = os.getenv('DB_HOST')
|
||||
db_port = os.getenv('DB_PORT')
|
||||
db_database = os.getenv('DB_NAME')
|
||||
db_user = os.getenv('DB_USER')
|
||||
db_password = os.getenv('DB_PASS')
|
||||
|
||||
engine = db.create_engine('postgresql://%s:%s@%s:%s/%s' % (db_user, db_password, db_host, db_port, db_database))
|
||||
|
||||
with engine.connect() as con:
|
||||
with con.begin():
|
||||
import_commands(server_id, all_warnings, con)
|
||||
Reference in New Issue
Block a user