Skip to content

Commit 03f2afc

Browse files
author
mydicebot
committed
19.8.21
1 parent 8b11df9 commit 03f2afc

File tree

9 files changed

+102
-123
lines changed

9 files changed

+102
-123
lines changed

screenshot/bot-logo-114.png

1.03 KB
Loading

src/api/controllers/apiController.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ exports.login = async function(req, res) {
5050
let dice = Factory.create(req.body.site);
5151
let ret = await dice.login(req.body.username, req.body.password, req.body.twofa, req.body.apikey, req);
5252
if(ret != true){
53-
res.render('login', {message:ret,site:req.params.site,skin:req.session.skin});
53+
res.render('login', {title: 'My Dice Bot',message:ret,site:req.params.site,skin:req.session.skin});
5454
} else {
55-
res.redirect(req.protocol+"://"+req.headers.host+'/'+req.body.site+'/info');
55+
res.redirect(req.protocol+"://"+req.headers.host+"/"+req.body.site+"/info");
5656
}
5757
} else {
58-
res.render('login',{site:req.params.site,skin:req.session.skin});
58+
res.render('login',{title: 'My Dice Bot',site:req.params.site,skin:req.session.skin});
5959
}
6060
} catch(err) {
6161
console.log(err);
62-
res.render('login', {message:err.toString(),site:req.params.site,skin:req.session.skin});
62+
res.render('login', {title: 'My Dice Bot',message:err.toString(),site:req.params.site,skin:req.session.skin});
6363
}
6464
};
6565

@@ -75,6 +75,7 @@ exports.info = async function(req, res) {
7575
ret.authSteem = encodeURIComponent(config.mydice.oauth.steem.url);
7676
ret.skin = req.session.skin;
7777
ret.codeSkin = 'default';
78+
ret.title = 'My Dice Bot';
7879
ret.url = config.mydice.url;
7980
if(req.session.skin == 'Contrast') {
8081
ret.codeSkin = 'night';
@@ -128,6 +129,9 @@ exports.keecheck = async function(req, res) {
128129
//filePath = path.resolve('/tmp/keepass/'+keepassfile+'.kdbx');
129130
filePath = path.resolve(path.join(__dirname, '../../keepass/'+keepassfile+'.kdbx'));
130131
}
132+
if(process.env.electron) {
133+
filePath = path.resolve(path.join(config.mydice.path, '/keepass/'+keepassfile+'.kdbx'));
134+
}
131135
if (fs.existsSync(filePath)) {
132136
return res.status(200).json(true);
133137
} else {
@@ -146,6 +150,9 @@ exports.keeload = async function(req, res) {
146150
//filePath = path.resolve('/tmp/keepass/'+req.body.keepassfile+'.kdbx');
147151
filePath = path.resolve(path.join(__dirname, '../../keepass/'+req.body.keepassfile+'.kdbx'));
148152
}
153+
if(process.env.electron) {
154+
filePath = path.resolve(path.join(config.mydice.path, '/keepass/'+req.body.keepassfile+'.kdbx'));
155+
}
149156
let cred = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(req.body.keepassword));
150157
let data = await fs.readFileSync(filePath);
151158
let db = await kdbxweb.Kdbx.load(new Uint8Array(data).buffer, cred);
@@ -179,6 +186,9 @@ exports.keereg = async function(req, res) {
179186
//filePath = path.resolve('/tmp/keepass/'+req.body.keepassfile+'.kdbx');
180187
filePath = path.resolve(path.join(__dirname, '../../keepass/'+req.body.keepassfile+'.kdbx'));
181188
}
189+
if(process.env.electron) {
190+
filePath = path.resolve(path.join(config.mydice.path, '/keepass/'+req.body.keepassfile+'.kdbx'));
191+
}
182192
let cred = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(req.body.keepassword));
183193
let db = kdbxweb.Kdbx.create(cred, 'mydicebot');
184194
//let subGroup = db.createGroup(db.getDefaultGroup(), 'mydicebot');
@@ -199,6 +209,9 @@ exports.keesave = async function(req, res) {
199209
//filePath = path.resolve('/tmp/keepass/'+req.body.keepassfile+'.kdbx');
200210
filePath = path.resolve(path.join(__dirname, '../../keepass/'+req.query.keepassfile+'.kdbx'));
201211
}
212+
if(process.env.electron) {
213+
filePath = path.resolve(path.join(config.mydice.path, '/keepass/'+req.query.keepassfile+'.kdbx'));
214+
}
202215
let cred = new kdbxweb.Credentials(kdbxweb.ProtectedValue.fromString(req.query.keepassword));
203216
let db = kdbxweb.Kdbx.create(cred, 'mydicebot');
204217
for(let k1 in req.body) {
@@ -239,6 +252,9 @@ exports.keefiles = async function(req, res) {
239252
//filePath = path.resolve('/tmp/keepass/');
240253
filePath = path.resolve(path.join(__dirname, '../../keepass/'));
241254
}
255+
if(process.env.electron) {
256+
filePath = path.resolve(path.join(config.mydice.path, '/keepass/'));
257+
}
242258
let paths = await getFiles(filePath, 'kdbx');
243259
return res.status(200).json(paths);
244260
} catch(err) {
@@ -259,6 +275,9 @@ exports.save = async function(req, res) {
259275
//filePath = path.resolve('/tmp/script/lua/'+fileName);
260276
filePath = path.resolve(path.join(__dirname, '../../script/'+ext+'/'+fileName));
261277
}
278+
if(process.env.electron) {
279+
filePath = path.resolve(path.join(config.mydice.path, '/script/'+ext+'/'+fileName));
280+
}
262281
let str = await writeFile(filePath, content);
263282
return res.status(200).json(str);
264283
} catch(err) {
@@ -277,6 +296,9 @@ exports.file = async function(req, res) {
277296
//filePath = path.resolve('/tmp/script/lua/'+req.query.file);
278297
filePath = path.resolve(path.join(__dirname, '../../script/'+ext+'/'+req.query.file));
279298
}
299+
if(process.env.electron) {
300+
filePath = path.resolve(path.join(config.mydice.path, '/script/'+ext+'/'+req.query.file));
301+
}
280302
let content = await readFile(filePath);
281303
return res.status(200).json(content);
282304
} catch(err) {
@@ -294,6 +316,9 @@ exports.script = async function(req, res) {
294316
//filePath = path.resolve('/tmp/script/lua/');
295317
filePath = path.resolve(path.join(__dirname, '../../script/'+ext+'/'));
296318
}
319+
if(process.env.electron) {
320+
filePath = path.resolve(path.join(config.mydice.path, '/script/'+ext+'/'));
321+
}
297322
let paths = await getFiles(filePath, ext);
298323
return res.status(200).json(paths);
299324
} catch(err) {
@@ -312,6 +337,9 @@ exports.del = async function(req, res) {
312337
//filePath = path.resolve('/tmp/script/lua/'+req.query.file);
313338
filePath = path.resolve(path.join(__dirname, '../../script/'+ext+'/'+req.query.file));
314339
}
340+
if(process.env.electron) {
341+
filePath = path.resolve(path.join(config.mydice.path, '/script/'+ext+'/'+req.query.file));
342+
}
315343
fs.unlinkSync(filePath);
316344
return res.status(200).json('ok');
317345
} catch(err) {
@@ -332,6 +360,9 @@ exports.upload = async function(req, res) {
332360
//filePath = path.resolve('/tmp/script/lua/'+files.upload.name);
333361
filePath = path.resolve(path.join(__dirname, '../../script/'+ext+'/'+files.upload.name));
334362
}
363+
if(process.env.electron) {
364+
filePath = path.resolve(path.join(config.mydice.path, '/script/'+ext+'/'+files.upload.name));
365+
}
335366
fs.writeFileSync(filePath, fs.readFileSync(files.upload.path));
336367
return res.status(200).json('ok');
337368
});

src/api/routes/api.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import {DuckDice} from '../models/duckdice';
1717
import {FreeBitco} from '../models/freebitco';
1818
import {WinDice} from '../models/windice';
1919
import {Factory} from '../models/factory';
20+
import config from 'config';
2021
import fs from 'fs';
2122
import path from 'path';
23+
import fse from 'fs-extra';
2224

2325
module.exports = function(app) {
2426
app.get('/', [checkSkin], api.index);
@@ -89,22 +91,43 @@ function checkScript(req, res, next) {
8991
if(isMobile(req)) {
9092
filePath = path.resolve(path.join(__dirname, '../../script/lua/'));
9193
}
94+
if(process.env.electron) {
95+
filePath = path.resolve(path.join(config.mydice.path, '/script/lua/'));
96+
}
9297
mkdir(filePath);
9398
filePath = path.resolve(path.join(process.execPath, '../script/js/'));
9499
if(isMobile(req)) {
95100
filePath = path.resolve(path.join(__dirname, '../../script/js/'));
96101
}
102+
if(process.env.electron) {
103+
filePath = path.resolve(path.join(config.mydice.path, '/script/js/'));
104+
}
97105
mkdir(filePath);
98106
filePath = path.resolve(path.join(process.execPath, '../script/py/'));
99107
if(isMobile(req)) {
100108
filePath = path.resolve(path.join(__dirname, '../../script/py/'));
101109
}
110+
if(process.env.electron) {
111+
filePath = path.resolve(path.join(config.mydice.path, '/script/py/'));
112+
}
102113
mkdir(filePath);
103114
filePath = path.resolve(path.join(process.execPath, '../keepass/'));
104115
if(isMobile(req)) {
105116
filePath = path.resolve(path.join(__dirname, '../../keepass/'));
106117
}
118+
if(process.env.electron) {
119+
filePath = path.resolve(path.join(config.mydice.path, '/keepass/'));
120+
}
107121
mkdir(filePath);
122+
if(process.env.electron) {
123+
try {
124+
fse.copySync(path.resolve(path.join(process.execPath, '../script/py/')),path.resolve(path.join(config.mydice.path, '/script/py/')),{ overwrite: false });
125+
fse.copySync(path.resolve(path.join(process.execPath, '../script/js/')),path.resolve(path.join(config.mydice.path, '/script/js/')),{ overwrite: false });
126+
fse.copySync(path.resolve(path.join(process.execPath, '../script/lua/')),path.resolve(path.join(config.mydice.path, '/script/lua/')),{ overwrite: false });
127+
} catch (err) {
128+
console.error(err)
129+
}
130+
}
108131
next();
109132
}
110133

src/app.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import bodyParser from 'body-parser';
66
import session from 'express-session';
77
import {createServer} from 'http';
88
import routes from './api/routes/api';
9-
import commandExists from 'command-exists'
109
import config from 'config'
11-
import execa from 'execa'
12-
import opn from 'opn'
1310

1411
let params = process.argv;
1512
let port = 57432;
@@ -20,31 +17,6 @@ if(portIndex != -1) {
2017
port = params.slice(portIndex+1,portIndex+2)[0];
2118
}
2219
}
23-
let browser = [];
24-
let browserIndex = params.indexOf('-browser');
25-
if(browserIndex != -1) {
26-
let reg = /^--[a-zA-Z0-9]+/;
27-
if(params.slice(browserIndex+1,browserIndex+2)[0] == 'chrome'){
28-
if (['darwin'].includes(process.platform)) {
29-
browser.push('Google Chrome');
30-
} else if (['win32'].includes(process.platform)) {
31-
browser.push('chrome');
32-
} else {
33-
browser.push('google-chrome');
34-
}
35-
} else {
36-
browser.push(params.slice(browserIndex+1,browserIndex+2)[0]);
37-
}
38-
if(reg.test(params.slice(browserIndex+2,browserIndex+3)[0])){
39-
browser.push(params.slice(browserIndex+2,browserIndex+3)[0]);
40-
}
41-
console.log(browser);
42-
}
43-
let consoleIndex = params.indexOf('-console');
44-
if(consoleIndex != -1) {
45-
console.log("console bet");
46-
}
47-
4820
let app = express();
4921
app.set('port', port);
5022
let server = createServer(app);
@@ -88,24 +60,4 @@ if(process.env.NODE_ENV == 'production' && typeof config.mydice =='undefined') {
8860
config.mydice.oauth.steem.url = 'https://app.steemconnect.com/oauth2/authorize?client_id=mydicebot&redirect_uri=https://auth.mydicebot.com/steem/cb&scope=login&response_type=code';
8961
}
9062

91-
console.log('pkg:',config.mydice.pkg);
9263
config.mydice.url = 'http://localhost:'+port;
93-
if (config.mydice.pkg) {
94-
let url = 'http://localhost:'+port+'/login';
95-
if (['win32', 'darwin'].includes(process.platform)) {
96-
opn(url, {
97-
wait: false,
98-
app:browser
99-
})
100-
} else {
101-
try {
102-
const xdgOpenExists = commandExists('xdg-open')
103-
if (!xdgOpenExists) {
104-
throw new Error('xdg-open does not exist')
105-
}
106-
execa('xdg-open', [url])
107-
} catch (_) {
108-
log(`Unable to open your browser automatically. Please open the following URI in your browser:\n\n${oAuthURL}\n\n`)
109-
}
110-
}
111-
}

0 commit comments

Comments
 (0)