Skip to content

Commit

Permalink
feat: Add Mix It Up quotes import
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderBrad committed Aug 10, 2023
1 parent b00b978 commit 1e45571
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/gui/app/directives/modals/quotes/import-quotes-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
<div class="modal-body pb-0">
<div ng-hide="$ctrl.quotes">
<h4>Import from</h5>
<p class="muted mb-12">Currently only quotes from Streamlabs Chatbot (desktop bot) can be imported.</p>
<p class="muted mb-12">Currently only quotes from Streamlabs Chatbot (desktop bot) and Mix It Up can be imported.</p>
<h4>Choose file</h4>
<p class="muted mb-8">To get the export file in Streamlabs Chatbot, go to Connections -> Cloud -> Create Split Excel and find the file called Quotes.xlsx.</p>
<p class="muted mb-2">To get the export file in Streamlabs Chatbot, go to Connections -> Cloud -> Create Split Excel and find the file called Quotes.xlsx.</p>
<p class="muted mb-8">To get the export file in Mix It Up, go to Quotes -> Export Quotes and find the file called Quotes.txt.</p>
<file-chooser
model="$ctrl.importFilePath"
on-update="$ctrl.onFileSelected(filepath)"
options="{filters: [ {name: 'Microsoft Excel', extensions: '.xlsx'}]}"
options="{filters: [ {name: 'Microsoft Excel', extensions: '.xlsx'}, {name: 'Text File', extensions: '.txt'} ]}"
hide-manual-edit="true"
>
</file-chooser>
Expand Down Expand Up @@ -97,7 +98,14 @@
];

$ctrl.onFileSelected = (filepath) => {
const data = importService.parseStreamlabsChatbotData(filepath);
//get the file type from the filepath
const fileType = filepath.split(".").pop();
let data;
if (fileType === "xlsx") {
data = importService.parseStreamlabsChatbotData(filepath);
} else if (fileType === "txt") {
data = importService.parseMixItUpData(filepath, "quotes");
}
if (data && data.quotes) {
$ctrl.quotes = data.quotes;
$ctrl.search = "";
Expand Down
34 changes: 34 additions & 0 deletions src/gui/app/services/import.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,40 @@
return data;
};

service.parseMixItUpData = (filepath, dataType) => {
if (dataType === "quotes") {
const data = {};
//split the file into lines either \r\n or \n
const file = fs.readFileSync(filepath, "utf8").split(/\r?\n/);
const header = file.shift();
if (header !== "# Quote Game Date/Time") {
return data;
}
//remove any empty lines
file.forEach((line, index) => {
if (line === "") {
file.splice(index, 1);
}
});
//split the file into quotes
const quotes = file.map(q => {
const splittedQuote = q.split("\t");
return {
_id: splittedQuote[0],
text: splittedQuote[1],
originator: "",
creator: "",
game: splittedQuote[2],
createdAt: splittedQuote[3]
};
});
//set the quotes property on the data object
data.quotes = quotes;
//return the data object
return data;
}
};

return service;
});
}());

0 comments on commit 1e45571

Please sign in to comment.