In the future, the bot should work with GitHub releases and warn the user when it is out of date with instructions to update. The ideal approach for development would be to slowly migrate each update with breaking changes that require migrations - as we see it in the following lines right now, for example:
|
// If some keys do not exist in the new settings read from file, set these settings back to the already stored value (before the read) |
|
if ( |
|
Object.keys(Settings._settings).some( |
|
(key: string): boolean => !(key in newSettings) |
|
) |
|
) { |
|
// Every key that exists in the new settings is being iterated over |
|
for (const untypedSetting of Object.keys(newSettings)) { |
|
// Type the setting key to be a valid key for the SettingsJSON array |
|
const setting: keyof SettingsJSON = |
|
untypedSetting as keyof SettingsJSON; |
|
// Store every found setting from the new settings into the local settings |
|
// @ts-ignore |
|
Settings._settings[setting] = newSettings[setting] as any; |
|
} |
|
changed = true; |
|
} |
|
// Backwards compatibility: This is a hard-coded checker to see if every streamer has a sent boolean because there was a version where it was not there |
|
for (const i of [ |
|
...Settings._settings['streamer-subscriptions'].entries(), |
|
] |
|
.filter( |
|
(channelWithIndex: [number, Channel]): boolean => |
|
channelWithIndex[1].sent === undefined |
|
) |
|
.map( |
|
(channelWithIndex: [number, Channel]): number => channelWithIndex[0] |
|
)) { |
|
Settings._settings['streamer-subscriptions'][i].sent = false; |
|
changed = true; |
|
} |
|
// Backwards compatibility: If users added streamers with invalid characters in previous versions of the bot, they get deleted |
|
if ( |
|
Settings._settings['streamer-subscriptions'].some( |
|
(channel: Channel): boolean => |
|
!channel.streamer.match(DMManager.validNameRegex) |
|
) |
|
) { |
|
Settings._settings['streamer-subscriptions'] = Settings._settings[ |
|
'streamer-subscriptions' |
|
].filter( |
|
(channel: Channel): boolean => |
|
!!channel.streamer.match(DMManager.validNameRegex) |
|
); |
|
changed = true; |
|
} |
|
if (changed) Settings.saveSettings(); |
In the future, the bot should work with GitHub releases and warn the user when it is out of date with instructions to update. The ideal approach for development would be to slowly migrate each update with breaking changes that require migrations - as we see it in the following lines right now, for example:
TrojanerBot/src/Settings.ts
Lines 62 to 108 in 4174061