当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript discord.js-commando.CommandMessage类代码示例

本文整理汇总了TypeScript中discord.js-commando.CommandMessage的典型用法代码示例。如果您正苦于以下问题:TypeScript js-commando.CommandMessage类的具体用法?TypeScript js-commando.CommandMessage怎么用?TypeScript js-commando.CommandMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了js-commando.CommandMessage类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: run

    public async run(msg: CommandMessage, args: { cardName: string }): Promise<Message | Message[]> {
        let filename: string

        if (!msg.channel.typing) { msg.channel.startTyping() }

        const card: Card = await CardData.findOne(args.cardName)
        if (card) { filename = await card.getImageFile('art') }

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

        if (!card) { return msg.reply(`sorry, I couldn't find a card with a name like '${args.cardName}'`) }
        if (!filename) { return msg.reply(`sorry, there was a problem getting the art for ${card.name}`) }

        const cleanFilename = path.basename(filename).replace('_', '')

        return msg.embed(
            new RichEmbed()
                .setTitle(card.name)
                .setURL(card.wikiUrl)
                .setColor(card.classColor)
                .addField('Artist', card.artist)
                .attachFile({ attachment: filename, name: cleanFilename })
                .setImage(`attachment://${cleanFilename}`)
        )
    }
开发者ID:tinnvec,项目名称:stonebot,代码行数:25,代码来源:art.ts

示例2: run

    public async run(msg: CommandMessage): Promise<Message | Message[]> {
        if (msg.channel instanceof TextChannel &&
            !msg.channel.permissionsFor(this.client.user).has('SEND_MESSAGES')) {
            return
        }

        const statsDisplay = stripIndents`
            Guilds: ${this.client.guilds.size}
            Channels: ${this.client.channels.size}
            Users: ${this.client.guilds.map((g: Guild) => g.memberCount).reduce((a, b) => a + b)}
        `

        if (msg.channel instanceof TextChannel &&
            !msg.channel.permissionsFor(this.client.user).has('EMBED_LINKS')) {
            return msg.say(stripIndents`
                **${this.client.user.username} Statistics**
                **Uptime**
                ${moment.duration(this.client.uptime).humanize()}
                **Memory Usage**
                ${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)}MB
                **General Stats**
                ${statsDisplay}
            `)
        }

        return msg.embed(
            new RichEmbed()
                .setTitle(`${this.client.user.username} Statistics`)
                .setThumbnail(this.client.user.displayAvatarURL)
                .addField('Uptime', moment.duration(this.client.uptime).humanize(), true)
                .addField('Memory Usage', `${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)}MB`, true)
                .addField('General Stats', statsDisplay, true)
        )
    }
开发者ID:tinnvec,项目名称:stonebot,代码行数:34,代码来源:stats.ts

示例3: run

    public async run(msg: CommandMessage, args: { bnetServer: string }): Promise<Message | Message[]> {
        const result = await CommunityDatabase.getQuestForUser(msg.author.id)

        // Are they completing?
        if (args.bnetServer === 'complete') {
            if (result) {
                return await CommunityDatabase.removeQuestsForUser(msg.author.id)
                    .then(() => msg.reply('congratulations! Removed your entry from those looking to trade quests.'))
            }
            return msg.reply('sorry, don\'t have you as looking to trade quests.')
        }

        const bnetServerDisplay = `Battle.net ${args.bnetServer} server`
        // Check if they're on the list
        if (result) {
            if (result.server === args.bnetServer) {
                return msg.reply(`already have you as looking to trade quests on the ${bnetServerDisplay}.`)
            }
            // Update entry to new server if different
            return await CommunityDatabase.updateQuestsForUser(msg.author.id, args.bnetServer)
                .then(() => msg.reply(
                    `updated your entry, now have you as looking to trade quests on the ${bnetServerDisplay}.`
                ))
        }

        // Check if another on the list shares a bnet and discord server
        let results = await CommunityDatabase.getQuestsForServer(args.bnetServer)
        if (results) {
            // Get only quests where users share a guild
            results = results.filter((q: any) => {
                return this.client.guilds.some((g) => {
                    return g.members.has(msg.author.id) && g.members.has(q.userId)
                })
            })
            if (results && results.length > 0) {
                const requestor = this.client.users.get(msg.author.id)
                const questHaver = this.client.users.get(results[0].user)
                await questHaver.send(oneLine`
                    Hello! I have you on my list of people looking to trade Hearthstone quests.
                    ${requestor} just told me they are also looking to trade on the ${bnetServerDisplay}.
                    Just contact them and enjoy your gold!\n\n
                    When you're all done, just tell me \`quest complete\`.
                `).catch(winston.error)
                return msg.reply(oneLine`
                    looks like someone you share a Discord server with is also looking to trade quests
                    on the ${bnetServerDisplay}! They should be contacting you soon.
                `)
            }
        }

        // Add them to the list
        return await CommunityDatabase.addQuestForUserOnServer(msg.author.id, args.bnetServer)
            .then(() => msg.reply(oneLine`
                can't find a match for you right now, but will let you know as soon as
                someone you share a Discord server with is also looking to trade quests on the ${bnetServerDisplay}.
            `))
    }
开发者ID:tinnvec,项目名称:stonebot,代码行数:57,代码来源:quest.ts

示例4: run

    public async run(msg: CommandMessage, args: { cardName: string }): Promise<Message | Message[]> {
        if (!msg.channel.typing) { msg.channel.startTyping() }

        const card: Card = await CardData.findOne(args.cardName)

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

        if (!card) { return msg.reply(`sorry, I couldn't find a card with a name like '${args.cardName}'`) }

        return msg.code('json', JSON.stringify(card.json, undefined, '  '))
    }
开发者ID:tinnvec,项目名称:stonebot,代码行数:11,代码来源:json.ts

示例5: run

    public async run(msg: CommandMessage, args: { cardName: string }): Promise<Message | Message[]> {
        let filename: string

        if (!msg.channel.typing) { msg.channel.startTyping() }

        const card: Card = await CardData.findOne(args.cardName)
        if (card) { filename = await card.getImageFile('gold') }

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

        if (!card) { return msg.reply(`sorry, I couldn't find a card with a name like '${args.cardName}'`) }
        if (!filename) { return msg.reply(`sorry, there was a problem getting the golden image for ${card.name}`) }

        return msg.say('', { file: { attachment: filename } })
    }
开发者ID:tinnvec,项目名称:stonebot,代码行数:15,代码来源:gold.ts

示例6: run

  async run(message: CommandMessage, { soundKey }: Kwargs): Promise<any> {
    const soundDir = path.join(__dirname, 'sounds')
    const { voiceChannel } = message.member

    // Commands are based on striped filenames minus mp3 extension
    const availableCommands = fs
      .readdirSync(soundDir)
      .map(sound => sound.slice(0, -4))

    /**
     * @description If not in a voice channel
     */
    if (!voiceChannel) {
      return await message.reply('tu dois rejoindre un channel :triumph:')
    }

    /**
     * @description If desired sound does not exist in folder
     */
    if (availableCommands.indexOf(soundKey) === -1) {
      return await message.reply(
        `ce son n'existe pas, mais voici ceux disponibles :
        ${availableCommands.map(command => `\n**${command}**`)}
      `
      )
    }

    /**
     * @description Join voice channel to play selected file
     */
    voiceChannel
      .join()
      .then(connection => {
        const dispatcher = connection.playFile(
          path.join(__dirname, 'sounds', `${soundKey}.mp3`)
        )
        dispatcher.setVolume(0.5)
        dispatcher.on('end', () => {
          voiceChannel.leave()
        })
      })
      .catch(console.error)
  }
开发者ID:antoine2vey,项目名称:BitusEnormus,代码行数:43,代码来源:play.ts

示例7: run

  async run(message: CommandMessage): Promise<any> {
    const { member, guild } = message

    if (member.voiceChannel) {
      // Send event to dispatcher in play.ts
      if (member.voiceChannel.connection.dispatcher) {
        const song = music.getNextMusic(guild.id)

        if (song) {
          message.channel.send(
            `Prochaine musique : ${song.title} - ${song.channelTitle}`
          )
        } else {
          message.reply(
            'ArrĂŞt de la musique ... (plus de musique dans la playlist)'
          )
        }

        member.voiceChannel.connection.dispatcher.end()
      } else {
        message.reply('Plus de musique dans la playlist')
      }
    }
  }
开发者ID:antoine2vey,项目名称:BitusEnormus,代码行数:24,代码来源:next.ts

示例8: 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

示例9:

 .then(() => msg.reply(
     `updated your entry, now have you as looking to trade quests on the ${bnetServerDisplay}.`
 ))
开发者ID:tinnvec,项目名称:stonebot,代码行数:3,代码来源:quest.ts


注:本文中的discord.js-commando.CommandMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。