1
+ import { Message , AttachmentBuilder } from "discord.js"
2
+ import { SlashCommandSubcommand , SlashCommandOption } from "../../structures/SlashCommandOption"
3
+ import { Command } from "../../structures/Command"
4
+ import { Embeds } from "../../structures/Embeds"
5
+ import { Functions } from "../../structures/Functions"
6
+ import { Kisaragi } from "../../structures/Kisaragi"
7
+ import { Permission } from "./../../structures/Permission"
8
+ import { students } from "blue-archive"
9
+ import path from "path"
10
+ import fs from "fs"
11
+
12
+ export default class BlueArchive extends Command {
13
+ private readonly defaults = [
14
+ "Shiroko" , "Alona" , "Hina" , "Hoshino" , "Hifumi" , "Koharu" , "Serika" , "Chise" ,
15
+ "Hikari" , "Nozomi" , "Yuuka" , "Serina" , "Shizuko" , "Miyu" , "Mari" , "Iroha" , "Momoi" ,
16
+ "Midori" , "Plana" , "Hanako" , "Azusa" , "Shun" , "Fuuka" , "Nagisa" , "Seia" , "Yuzu" ,
17
+ "Toki" , "Mika" , "Aris" , "Miyako"
18
+ ]
19
+ constructor ( discord : Kisaragi , message : Message ) {
20
+ super ( discord , message , {
21
+ description : "Searches for a blue archive character." ,
22
+ help :
23
+ `
24
+ \`bluearchive\` - Gets some picked characters.
25
+ \`bluearchive character\` - Gets information on the character.
26
+ ` ,
27
+ examples :
28
+ `
29
+ \`=>bluearchive shiroko\`
30
+ \`=>bluearchive hoshino\`
31
+ ` ,
32
+ aliases : [ "ba" ] ,
33
+ random : "none" ,
34
+ cooldown : 10 ,
35
+ subcommandEnabled : true
36
+ } )
37
+ const characterOption = new SlashCommandOption ( )
38
+ . setType ( "string" )
39
+ . setName ( "character" )
40
+ . setDescription ( "Character to search for." )
41
+
42
+ this . subcommand = new SlashCommandSubcommand ( )
43
+ . setName ( this . constructor . name . toLowerCase ( ) )
44
+ . setDescription ( this . options . description )
45
+ . addOption ( characterOption )
46
+ }
47
+
48
+ public run = async ( args : string [ ] ) => {
49
+ const discord = this . discord
50
+ const message = this . message
51
+ const embeds = new Embeds ( discord , message )
52
+ const perms = new Permission ( discord , message )
53
+ if ( discord . checkMuted ( message ) ) if ( ! perms . checkNSFW ( ) ) return
54
+ let query = Functions . combineArgs ( args , 1 ) . trim ( ) . replace ( / + / g, "-" )
55
+ if ( ! query ) {
56
+ query = this . defaults [ Math . floor ( Math . random ( ) * this . defaults . length ) ] . trim ( )
57
+ }
58
+ const studentCN = students . queryByName ( query ) ?. [ 0 ]
59
+ if ( ! studentCN ) {
60
+ return this . invalidQuery ( embeds . createEmbed ( )
61
+ . setAuthor ( { name : "bluearchive" , iconURL : "https://kisaragi.moe/assets/embed/bluearchive.png" } )
62
+ . setTitle ( `**Blue Archive Search** ${ discord . getEmoji ( "midoriHug" ) } ` ) )
63
+ }
64
+ const student = students . getById ( studentCN . Id , "en" )
65
+
66
+ const iconPath = path . join ( __dirname , `../../../node_modules/blue-archive/assets/icons/${ student . PathName } .png` )
67
+ const imagePath = path . join ( __dirname , `../../../node_modules/blue-archive/assets/portraits/${ student . DevName } .webp` )
68
+
69
+ let attachments = [ ] as AttachmentBuilder [ ]
70
+ if ( fs . existsSync ( iconPath ) ) {
71
+ const iconAttachment = new AttachmentBuilder ( fs . readFileSync ( iconPath ) , { name : "thumbnail.png" } )
72
+ attachments . push ( iconAttachment )
73
+ }
74
+ if ( fs . existsSync ( imagePath ) ) {
75
+ const imageAttachment = new AttachmentBuilder ( fs . readFileSync ( imagePath ) , { name : "image.png" } )
76
+ attachments . push ( imageAttachment )
77
+ }
78
+
79
+ const blueArchiveEmbed = embeds . createEmbed ( )
80
+ blueArchiveEmbed
81
+ . setAuthor ( { name : "bluearchive" , iconURL : "https://kisaragi.moe/assets/embed/bluearchive.png" } )
82
+ . setTitle ( `**Blue Archive Search** ${ discord . getEmoji ( "midoriHug" ) } ` )
83
+ . setURL ( `https://bluearchive.fandom.com/wiki/${ student . Name } ` )
84
+ . setThumbnail ( "attachment://thumbnail.png" )
85
+ . setImage ( "attachment://image.png" )
86
+ . setDescription (
87
+ `${ discord . getEmoji ( "star" ) } _Character:_ **${ student . FamilyName } ${ student . Name } **\n` +
88
+ `${ discord . getEmoji ( "star" ) } _School:_ **${ student . School } **\n` +
89
+ `${ discord . getEmoji ( "star" ) } _Club:_ **${ student . Club } **\n` +
90
+ `${ discord . getEmoji ( "star" ) } _Star Grade:_ **${ student . StarGrade } ${ discord . getEmoji ( "starYellow" ) } **\n` +
91
+ `${ discord . getEmoji ( "star" ) } _Age:_ **${ student . CharacterAge } **\n` +
92
+ `${ discord . getEmoji ( "star" ) } _Height:_ **${ student . CharHeightImperial } **\n` +
93
+ `${ discord . getEmoji ( "star" ) } _Birthday:_ **${ student . Birthday } **\n` +
94
+ `${ discord . getEmoji ( "star" ) } _Hobby:_ ${ student . Hobby } \n` +
95
+ `${ discord . getEmoji ( "star" ) } _Description:_ ${ student . ProfileIntroduction } \n`
96
+ )
97
+ return this . reply ( blueArchiveEmbed , attachments )
98
+ }
99
+ }
0 commit comments