Skip to content

Commit

Permalink
Merge serveroptions into configs, and do class wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
iSwanGit committed Mar 20, 2021
1 parent 73b47f0 commit c4aee5d
Show file tree
Hide file tree
Showing 6 changed files with 1,924 additions and 1,879 deletions.
24 changes: 22 additions & 2 deletions DJYurikaDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { keys } from './config';
import { Config, Song } from './types';
import { getRandomInt } from './util';

class DJYurikaDB {
export class DJYurikaDB {
private pool: Pool;
// private songList: Array<DBSong>;

Expand All @@ -14,14 +14,23 @@ class DJYurikaDB {
private async init() {
try {
this.pool = await createPool(keys.dbServer);
console.log('DB pool created')
// const conn = await this.pool.getConnection();
// this.songList = await conn.query("SELECT * FROM playlist");
// conn.end();
}
catch (err) { console.error(err); }
}

public async loadConfig(server: string) {
public async waitAndCheckPoolCreated() {
if (!this.pool) {
setTimeout(() => {
this.waitAndCheckPoolCreated();
}, 100);
}
}

public async loadConfig(server: string): Promise<Config> {
try {
const conn = await this.pool.getConnection();
const config = (await conn.query(`SELECT volume FROM config WHERE server = ?`, server))[0] as Config;
Expand All @@ -32,6 +41,17 @@ class DJYurikaDB {
catch (err) { console.error(err); throw err; }
}

public async loadAllConfig(): Promise<Config[]> {
try {
const conn = await this.pool.getConnection();
const configs = (await conn.query(`SELECT * FROM config`)) as Config[];

conn.end();
return configs;
}
catch (err) { console.error(err); throw err; }
}

public async saveConfig(config: Config, server: string) {
try {
const conn = await this.pool.getConnection();
Expand Down
11 changes: 11 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import consoleStamp from 'console-stamp';
import { DJYurika } from './djyurika';

consoleStamp(console, {
pattern: 'yyyy/mm/dd HH:MM:ss.l',
});

process.setMaxListeners(0); // release limit (for voicestatechange event handler)

const djyurika = new DJYurika();
djyurika.start();
30 changes: 1 addition & 29 deletions config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,8 @@ export const environment = {
volume: 35,
},
githubRepoUrl: 'https://github.com/MikuWallets/djyurika_js',

serverOptions: [
{
serverID: '759404553451601920', // mmk
developerRoleID: '760741584492298251',
moderatorRoleID: '760806219509137418',
commandChannelID: '810524606812651520',
// commandChannelID: '762474528840351774', // bot-command
},
{
serverID: '706826945010204743', // mikuwallets
developerRoleID: '757615133412425850', // admin
moderatorRoleID: null,
commandChannelID: '818104757822029865', // dj-yurika-command
},
{
serverID: '478916169340813312', // 고양이월드
developerRoleID: '819628441838026753', // Yurika Father
moderatorRoleID: null,
commandChannelID: '810144835499065344', // 노래신청방
},
{
serverID: '720598754398568568', // 오동석(psy)
developerRoleID: null,
moderatorRoleID: null,
commandChannelID: '720598754398568572', // 일반
},
],

searchApiUrl: 'https://www.googleapis.com/youtube/v3/search',
youtubeUrlPrefix: 'https://www.youtube.com/watch?v=',
maxSearchResults: 5,
refreshInterval: 13000,
}
Loading

0 comments on commit c4aee5d

Please sign in to comment.