當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript js.RichEmbed.addField方法代碼示例

本文整理匯總了TypeScript中discord.js.RichEmbed.addField方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript js.RichEmbed.addField方法的具體用法?TypeScript js.RichEmbed.addField怎麽用?TypeScript js.RichEmbed.addField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在discord.js.RichEmbed的用法示例。


在下文中一共展示了js.RichEmbed.addField方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: warn

  warn(info: string, callback?: () => void) {
    this.findInfo();
    if (this.client.readyAt == null) { return; }

    const embed = new RichEmbed();
    embed.setAuthor("Weeb Bot");
    embed.setColor("RED");
    embed.addField("WARNING", info);

    this.channel.send(embed);
  }
開發者ID:KazeSenoue,項目名稱:WeebBot-v2,代碼行數:11,代碼來源:discordTransporter.ts

示例2: parseInt

 valueKeywords.forEach((vk) => {
     let key = vk.split(':')[0]
     const value = vk.split(':')[1]
     if (key === 'mana') { key = 'cost' }
     let filter
     if (key === 'artist') {
         winston.debug(`Filtering cards for artist name that includes '${value}'.`)
         filter = (card: Card) => {
             return card.artist && card.artist.toLowerCase().includes(value.toLowerCase())
         }
         searchEmbed.addField('Artist', `Name contains '${value}'`, true)
     } else {
         if (value.endsWith('+')) {
             const num: number = parseInt(value.slice(0, -1), 10)
             winston.debug(`Filtering cards for '${key}' >= '${num}'.`)
             // @ts-ignore: No index defined on Card class currently
             filter = (card: Card) => card[key] >= num
             searchEmbed.addField(key, `${num} or more`, true)
         } else if (value.endsWith('-')) {
             const num: number = parseInt(value.slice(0, -1), 10)
             winston.debug(`Filtering cards for '${key}' <= '${num}'.`)
             // @ts-ignore: No index defined on Card class currently
             filter = (card: Card) => card[key] <= num
             searchEmbed.addField(key, `${num} or less`, true)
         } else if (value.includes('-')) {
             const min: number = parseInt(value.split('-')[0], 10)
             const max: number = parseInt(value.split('-')[1], 10)
             winston.debug(`Filtering cards for '${key}' between '${min}' and '${max}'.`)
             // @ts-ignore: No index defined on Card class currently
             filter = (card: Card) => card[key] >= min && card[key] <= max
             searchEmbed.addField(key, `Between ${min} and ${max}`, true)
         } else {
             winston.debug(`Filtering cards for '${key}' == '${value}'.`)
             // @ts-ignore: No index defined on Card class currently
             filter = (card: Card) => card[key] === parseInt(value, 10)
             searchEmbed.addField(key, `Equal to ${value}`, true)
         }
     }
     cards = cards.filter(filter)
 }, this)
開發者ID:tinnvec,項目名稱:stonebot,代碼行數:40,代碼來源:search.ts

示例3: run

    public async run(msg: CommandMessage, args: string[]) {
        if (!msg.channel.typing) { msg.channel.startTyping() }

        winston.debug('Fetching all cards.')
        let cards: Card[] = await CardData.getLatest()

        if (msg.channel.typing) { msg.channel.stopTyping() }

        const valueKeywords: string[] = []
        const words: string[] = []

        args.forEach((arg) => {
            arg = arg.toLowerCase()
            if (arg.includes(':')) {
                valueKeywords.push(arg)
            } else {
                words.push(arg)
            }
        }, this)

        cards = cards.filter((card) => card.collectible && card.type !== 'HERO')
        const searchEmbed: RichEmbed = new RichEmbed()

        if (valueKeywords.length > 0) {
            valueKeywords.forEach((vk) => {
                let key = vk.split(':')[0]
                const value = vk.split(':')[1]
                if (key === 'mana') { key = 'cost' }
                let filter
                if (key === 'artist') {
                    winston.debug(`Filtering cards for artist name that includes '${value}'.`)
                    filter = (card: Card) => {
                        return card.artist && card.artist.toLowerCase().includes(value.toLowerCase())
                    }
                    searchEmbed.addField('Artist', `Name contains '${value}'`, true)
                } else {
                    if (value.endsWith('+')) {
                        const num: number = parseInt(value.slice(0, -1), 10)
                        winston.debug(`Filtering cards for '${key}' >= '${num}'.`)
                        // @ts-ignore: No index defined on Card class currently
                        filter = (card: Card) => card[key] >= num
                        searchEmbed.addField(key, `${num} or more`, true)
                    } else if (value.endsWith('-')) {
                        const num: number = parseInt(value.slice(0, -1), 10)
                        winston.debug(`Filtering cards for '${key}' <= '${num}'.`)
                        // @ts-ignore: No index defined on Card class currently
                        filter = (card: Card) => card[key] <= num
                        searchEmbed.addField(key, `${num} or less`, true)
                    } else if (value.includes('-')) {
                        const min: number = parseInt(value.split('-')[0], 10)
                        const max: number = parseInt(value.split('-')[1], 10)
                        winston.debug(`Filtering cards for '${key}' between '${min}' and '${max}'.`)
                        // @ts-ignore: No index defined on Card class currently
                        filter = (card: Card) => card[key] >= min && card[key] <= max
                        searchEmbed.addField(key, `Between ${min} and ${max}`, true)
                    } else {
                        winston.debug(`Filtering cards for '${key}' == '${value}'.`)
                        // @ts-ignore: No index defined on Card class currently
                        filter = (card: Card) => card[key] === parseInt(value, 10)
                        searchEmbed.addField(key, `Equal to ${value}`, true)
                    }
                }
                cards = cards.filter(filter)
            }, this)
        }

        if (words.length > 0) {
            const searchTerm: string = words.join(' ').toLowerCase()
            const searchKeys: string[] = ['name', 'playerClass', 'race', 'rarity', 'text', 'type']
            winston.debug(`Searching cards for '${searchTerm}'.`)
            cards = cards.filter((card: Card) => {
                // @ts-ignore: No index defined on Card class currently
                return (searchKeys.some((key: string) => card[key] && card[key].toLowerCase().includes(searchTerm)) ||
                (card.set && this.cardSetMatches(card.set, searchTerm)))
            })
            searchEmbed.addField('Search Term', searchTerm, true)
        }

        winston.debug('Sorting cards by name')
        cards.sort((a, b) => {
            const nameA: string = a.name.toLowerCase()
            const nameB: string = b.name.toLowerCase()
            if (nameA < nameB) { return -1 }
            if (nameA > nameB) { return 1 }
            return 0
        })

        let results = '_Sorry, got nothing_'
        if (cards.length > 0) {
            results = oneLine`
                _Found ${cards.length} card${cards.length === 1 ? '' : 's'}
                that match${cards.length === 1 ? 'es' : ''}._
            `
            if (cards.length > MAX_RESULTS) { results += ` _Here are the first ${MAX_RESULTS}._` }
            const cardNames: string[] = cards.slice(0, MAX_RESULTS).map((c: Card) => c.name)
            results += '\n' + cardNames.map((n) => {
                return `[${n}](http://hearthstone.gamepedia.com/${n.replace(/\s/g, '_')})`
            }).join(' | ')
        }
        searchEmbed.addField('Results', results)
//.........這裏部分代碼省略.........
開發者ID:tinnvec,項目名稱:stonebot,代碼行數:101,代碼來源:search.ts


注:本文中的discord.js.RichEmbed.addField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。