Skip to content

Commit

Permalink
fix(Config): v1 api key optional (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumatan authored Mar 13, 2022
1 parent e00b084 commit 44cd092
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/App/modules/Bot/components/Start.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { connect } from 'react-redux';
import injectSheet from 'react-jss';
import start from '../../../../Bot';
import Toggle from '../../common/Toggle';
import { getOsuApiKey } from '../../Settings/reducer/selectors'

const styles = {
Start: {
Expand All @@ -24,15 +25,15 @@ const Start = ({ classes, connected, irc, osuApi }) => {
<p>{connected ? (connected === 'connecting' ? 'Connecting to Bancho via IRC..' : 'Online') : 'Offline'}</p>
{notReady ? (
<p style={{ margin: 'auto 10px' }}>
Warning: no irc credential or osu API key found. Please go to settings section
Warning: no irc credential found. Please go to settings section
</p>
) : null}
</div>
);
};

const mapStateToProps = ({ settings }) => ({
irc: settings.userPreferences.irc,
osuApi: settings.userPreferences.osuApi.key,
const mapStateToProps = (state) => ({
irc: state.settings.userPreferences.irc,
osuApi: getOsuApiKey(state),
});
export default connect(mapStateToProps)(injectSheet(styles)(Start));
2 changes: 1 addition & 1 deletion src/App/modules/Settings/helpers/baseConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default Object.freeze({
isBotAccount: false,
},
osuApi: {
key: process.env.API_KEY_V1,
key: "",
},
},
beatconnectAPI: {
Expand Down
2 changes: 1 addition & 1 deletion src/App/modules/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const Settings = ({ userPreferences }) => {
{ name: 'Password', value: irc.password, action: setIrcPass, type: String, pass: true },
],
Misc: [
{ name: 'Osu api key', value: osuApi.key, action: setOSUApiKey, type: String, pass: true },
{ name: 'Osu api key (optional)', value: osuApi.key, action: setOSUApiKey, type: String, pass: true },
{ name: 'Bot prefix', value: prefix, action: setPrefix, type: String },
],
},
Expand Down
5 changes: 5 additions & 0 deletions src/App/modules/Settings/reducer/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ export const getVolume = state => _.get(getUserPreference(state), ['volume'], nu
export const getOsuSongPath = state => _.get(getUserPreference(state), ['osuSongsPath'], null);

export const getOsuPath = state => _.get(getUserPreference(state), ['osuPath'], null);

export const getOsuApiKey = state => {
let apiKey = _.get(getUserPreference(state), ['osuApi', 'key'], '');
return _.isEmpty(apiKey.trim()) ? process.env.BEATCONNECT_CLIENT_API_KEY_V1 : apiKey;
};
15 changes: 13 additions & 2 deletions src/Bot/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import Bot from './Bot';
import store from '../shared/store';
import { getOsuApiKey } from '../App/modules/Settings/reducer/selectors';

export default () => {
const { settings, bot } = store.getState();
const state = store.getState();
const { bot } = state;
const botSettings = {
...state.settings,
userPreferences: {
...state.settings.userPreferences,
osuApi: { ...state.settings.userPreferences.osuApi, key: getOsuApiKey(state) },
},
};

const { connected, instance } = bot;

if (!instance.connect) {
console.log('connecting using new Bot');
store.dispatch({ type: 'CONNECT', payload: { status: 'connecting', instance: new Bot(settings) } });
store.dispatch({ type: 'CONNECT', payload: { status: 'connecting', instance: new Bot(botSettings) } });
} else if (connected) {
console.log('disconnecting');
instance.disconnect();
Expand Down

0 comments on commit 44cd092

Please sign in to comment.