generated from KevinNovak/Discord-Bot-TypeScript-Template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
79 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Region } from '../../constants/regions'; | ||
|
||
export function idToRange(id: number): Region { | ||
if (id >= 42e8) { | ||
throw new Error('bot id'); | ||
} else if (id >= 31e8) { | ||
throw new Error('china id'); | ||
} else if (id >= 20e8) { | ||
return 'asia'; | ||
} else if (id >= 10e8) { | ||
return 'com'; | ||
} else if (id >= 5e8) { | ||
return 'eu'; | ||
} else if (id >= 0) { | ||
throw new Error('ru id'); | ||
} else { | ||
throw new Error(`id ${id} is out of range`); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { usersDatabase } from '../../databases/users'; | ||
import { idToRange } from '../blitz/idToRegion'; | ||
|
||
export async function flagUserActivity(blitz: number) { | ||
await usersDatabase.users.upsert({ | ||
where: { blitz }, | ||
update: {}, | ||
create: { blitz }, | ||
}); | ||
} | ||
|
||
export async function linkBlitzAndDiscord(discord: bigint, blitz: number) { | ||
await usersDatabase.discordUsers.upsert({ | ||
where: { discord }, | ||
update: { blitz }, | ||
create: { discord, blitz }, | ||
}); | ||
await flagUserActivity(blitz); | ||
} | ||
|
||
export async function getBlitzFromDiscord(discord: bigint) { | ||
const unique = await usersDatabase.discordUsers.findUnique({ | ||
where: { discord }, | ||
}); | ||
|
||
if (unique === null) return null; | ||
|
||
await flagUserActivity(unique.blitz); | ||
return { id: unique.blitz, region: idToRange(unique.blitz) }; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
export const usersDatabase = new PrismaClient(); |