本文整理汇总了TypeScript中discord.js.RichEmbed类的典型用法代码示例。如果您正苦于以下问题:TypeScript js.RichEmbed类的具体用法?TypeScript js.RichEmbed怎么用?TypeScript js.RichEmbed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了js.RichEmbed类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: GetEmbedForReply
public async GetEmbedForReply(
event: IMatrixEvent,
channel: Discord.TextChannel,
): Promise<Discord.RichEmbed|undefined> {
if (!event.content) {
event.content = {};
}
const relatesTo = event.content["m.relates_to"];
let eventId = "";
if (relatesTo && relatesTo["m.in_reply_to"]) {
eventId = relatesTo["m.in_reply_to"].event_id;
} else {
return;
}
const intent = this.bridge.getIntent();
// Try to get the event.
try {
const sourceEvent = await intent.getEvent(event.room_id, eventId);
sourceEvent.content.body = sourceEvent.content.body || "Reply with unknown content";
const replyEmbed = (await this.EventToEmbed(sourceEvent, channel, false)).messageEmbed;
// if we reply to a discord member, ping them!
if (this.bridge.getBot().isRemoteUser(sourceEvent.sender)) {
const uid = new MatrixUser(sourceEvent.sender.replace("@", "")).localpart.substring("_discord".length);
replyEmbed.addField("ping", `<@${uid}>`);
}
replyEmbed.setTimestamp(new Date(sourceEvent.origin_server_ts));
if (this.HasAttachment(sourceEvent)) {
const mxClient = this.bridge.getClientFactory().getClientAs();
const url = mxClient.mxcUrlToHttp(sourceEvent.content.url);
if (["m.image", "m.sticker"].includes(sourceEvent.content.msgtype as string)
|| sourceEvent.type === "m.sticker") {
// we have an image reply
replyEmbed.setImage(url);
} else {
const name = this.GetFilenameForMediaEvent(sourceEvent.content);
replyEmbed.description = `[${name}](${url})`;
}
}
return replyEmbed;
} catch (ex) {
log.warn("Failed to handle reply, showing a unknown embed:", ex);
}
// For some reason we failed to get the event, so using fallback.
const embed = new Discord.RichEmbed();
embed.setDescription("Reply with unknown content");
embed.setAuthor("Unknown");
return embed;
}
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:53,代码来源:matrixeventprocessor.ts
示例3: EventToEmbed
public async EventToEmbed(
event: IMatrixEvent, channel: Discord.TextChannel, getReply: boolean = true,
): Promise<IMatrixEventProcessorResult> {
const mxClient = this.bridge.getClientFactory().getClientAs();
let profile: IMatrixEvent | null = null;
try {
profile = await mxClient.getStateEvent(event.room_id, "m.room.member", event.sender);
if (!profile) {
profile = await mxClient.getProfileInfo(event.sender);
}
if (!profile) {
log.warn(`User ${event.sender} has no member state and no profile. That's odd.`);
}
} catch (err) {
log.warn(`Trying to fetch member state or profile for ${event.sender} failed`, err);
}
const params = {
mxClient,
roomId: event.room_id,
userId: event.sender,
} as IMatrixMessageProcessorParams;
if (profile) {
params.displayname = profile.displayname;
}
let body: string = "";
if (event.type !== "m.sticker") {
body = await this.matrixMsgProcessor.FormatMessage(event.content as IMatrixMessage, channel.guild, params);
}
const messageEmbed = new Discord.RichEmbed();
messageEmbed.setDescription(body);
await this.SetEmbedAuthor(messageEmbed, event.sender, profile);
const replyEmbed = getReply ? (await this.GetEmbedForReply(event, channel)) : undefined;
if (replyEmbed && replyEmbed.fields) {
for (let i = 0; i < replyEmbed.fields.length; i++) {
const f = replyEmbed.fields[i];
if (f.name === "ping") {
messageEmbed.description += `\n(${f.value})`;
replyEmbed.fields.splice(i, 1);
break;
}
}
}
return {
messageEmbed,
replyEmbed,
};
}
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:50,代码来源:matrixeventprocessor.ts
示例4:
const buildMessage = (eqs: IEQ[], ships: number[]) => {
let shipnumbers = [":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:", ":keycap_ten:"];
const embed = new Discord.RichEmbed();
embed.setAuthor("PSO2 Emergency Quest Alert", "https://images.emojiterra.com/mozilla/512px/231a.png");
embed.setColor("GREEN");
embed.setDescription('<:H_Line_Bold:386614101503246348>Ships<:H_Line_Bold:386614101503246348>');
eqs
.filter(eq => ships.includes(eq.ship))
.forEach(eq => {
embed.description += `\n ⢠${shipnumbers[eq.ship - 1]}<:V_Line:386619978994024458>${eq.name}`;
});
if (eqs.length > 9) {
embed.setDescription('<:H_Line_Bold:386614101503246348>All Ships<:H_Line_Bold:386614101503246348>');
embed.description += `\n ⢠${eqs[0].name}`;
}
embed.description += "\n\n[Help?](https://bit.ly/2KRb1De)";
return embed;
}
开发者ID:KazeSenoue,项目名称:WeebBot-v2,代码行数:18,代码来源:eqs.ts
示例5: 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
示例6: 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
注:本文中的discord.js.RichEmbed类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论