Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(settings): add battle notifier settings #616

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

PabloCorso
Copy link
Collaborator

@PabloCorso PabloCorso commented Jun 28, 2023

Battle Notifier migration discussion here.

What changes are proposed in this pull request?

Add new bn_kuski_rule table and update setting table to store notification settings.

- setting
  + BnEnabled: boolean // turn notifications on/off 
+ bn_kuski_rule
  + BnKuskiRuleIndex: number
  + KuskiIndex: number // multiple rules per kuski
  + BattleTypes: string // Normal,First Finish,One Life
  + Designers: string // Kopaka,Igge
  + LevelPatterns: string // Pob.lev,jbl.lev
  + BattleAttributes string // see others,drunk 
  + MinDuration: number // minutes
  + MaxDuration: number // minutes
  + IgnoreList: boolean // is rule for ignore list
  • Endpoints:
    • GET api/bn/:DiscordId - get user settings if DiscordId exists in DB.
    • SET api/bn/:DiscordId - override user notification rules
      • First time the user sets notification rules, settings BnEnabled should be set to true.
    • GET api/bn - gets all "active" settings with BnEnabled and at least one BnKuskiRule
    • SET api/bn/:DiscordId/toggle/:BnEnabled - turn notifications on/off (BnEnabled)
    • GET api/bn/:DiscordId/linked - does DiscordId exist in DB

@PabloCorso
Copy link
Collaborator Author

PabloCorso commented Jun 28, 2023

Must be addressed

  • For this new endpoints there is no authentication in place, so the endpoints are public? Haven't checked yet on how this could be done in this case. This endpoints would only be accessed by the Discord bot server.
  • Manual migration from current bn.store.json user settings to the database, so that active users are not affected.

@PabloCorso
Copy link
Collaborator Author

Must be addressed

  • For this new endpoints there is no authentication in place, so the endpoints are public? Haven't checked yet on how this could be done in this case. This endpoints would only be accessed by the Discord bot server.
  • Manual migration from current bn.store.json user settings to the database, so that active users are not affected.
  1. For the auth made middleware authDiscord with configurable authorization token.

  2. For the manual migration of data I can make SQL inserts from current bn.store.json.

@PabloCorso PabloCorso requested a review from sunehs June 28, 2023 17:51
@PabloCorso PabloCorso force-pushed the bn-store-to-db branch 3 times, most recently from 8741085 to 0b51378 Compare June 29, 2023 12:54
@PabloCorso
Copy link
Collaborator Author

PabloCorso commented Jun 29, 2023

Got migration SQL script from bn.store.json data. I don't have KuskiIndex for users since we only stored DiscordId, but do have Discord username so can easily map them out.

allowNull: false,
defaultValue: 0,
},
CreatedAt: {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these for now

return get;
};

const ChangeBnEnabledSettings = async data => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to singular

const rules = await BnKuskiRule.findAll({
where: { KuskiIndex: setting.KuskiIndex },
});
const isFirstTimeSetup = !rules.length && data.BnKuskiRules.length > 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened in "Any by any" rule? Is rule being created as empty? Is it considered first setup here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked and notify "Any" battle creates an empty rule (no designers, no battle types, etc...) which is expected behaviour with current bot logic. Found a bug that made every update turn BnEnabled off. Fix: only update BnEnabled in first time setup. Otherwise only update BnEnabled via toggle endpoint.

{ where: { KuskiIndex: setting.KuskiIndex } },
);

// delete all BnKuskiRules from this user
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to simplify this a little bit with better methods from sequelize but could not use those recommended magic methods. This is where I miss TypeScript most times, while using libraries without much API help at code level.

@@ -0,0 +1,6 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason for adding this? it's already in .eslintrc.json

Comment on lines +52 to +53
jwtSecret:
'eAwI4zcTDd4Pvc8QtN9z57Fqsr4ENNcTpK1x4A1dCLj0Y44OravXZDzNbA-4VEwAIh1Hw3vn1nhB9ygWLqAGE4GiX6hjjLsJi8IJ',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has eslint ignore above, something about your settings or the new .prettierrc.json forcing it anyway?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants