Last active
March 25, 2019 12:49
-
-
Save goldblade/dca756c52510ba1a0a4d32b253c8342f to your computer and use it in GitHub Desktop.
atena
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const save = async data => { | |
| if (isBot(data)) { | |
| return; | |
| } | |
| let valid = true; | |
| let interaction; | |
| // apply valid function to others integrations | |
| if (data.origin === "rocket") { | |
| await exportFunctions | |
| .validInteraction(data) | |
| .then(() => { | |
| interaction = rocketController.normalize(data); | |
| }) | |
| .catch(() => { | |
| valid = false; | |
| }); | |
| } else { | |
| interaction = exportFunctions.normalize(data); | |
| } | |
| if (valid) { | |
| const todayLimitScore = config.xprules.limits.daily; | |
| const score = await exportFunctions.todayScore(interaction.user); | |
| const todayLimitStatus = todayLimitScore - score; | |
| const instance = interactionModel(interaction); | |
| const maxSeconds = 5; | |
| analyticsSendCollect(interaction); | |
| if ( | |
| interaction.type === "message" && | |
| moment(interaction.date).diff( | |
| await lastMessageTime(instance), | |
| "seconds" | |
| ) < maxSeconds | |
| ) { | |
| console.log("FLOOD"); | |
| return _throw("User makes flood"); | |
| } | |
| if (todayLimitStatus > 0 || !todayLimitStatus) { | |
| instance.score = calculateScore(interaction); | |
| await userController.update(interaction); | |
| // await achievementController.save(interaction); | |
| // await achievementTemporaryController.save(interaction); | |
| if ( | |
| ![ | |
| "message", | |
| "issue", | |
| "review", | |
| "pull_request", | |
| "merged_pull_request", | |
| "comment" | |
| ].includes(interaction.type) && | |
| interaction.parentUser !== interaction.user | |
| ) { | |
| await userController.updateParentUser(interaction); | |
| } | |
| } | |
| // const instance = interactionModel(interaction); | |
| return await instance.save(); | |
| } else { | |
| return new Promise((resolve, reject) => { | |
| reject("add new interaction"); | |
| }); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment