-
Notifications
You must be signed in to change notification settings - Fork 2
/
guildMemberAdd.ts
74 lines (57 loc) · 2.33 KB
/
guildMemberAdd.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*!
* Coded by CallMeKory - https://github.com/callmekory
* 'It’s not a bug – it’s an undocumented feature.'
*/
import Canvas from 'canvas'
import { Attachment, GuildMember, TextChannel } from 'discord.js'
import path from 'path'
import { database } from '../core/database/database'
export const guildMemberAdd = async (member: GuildMember) => {
const db = await database.models.ServerConfig.findOne({ where: { id: member.guild.id } })
const { welcomeChannel, prefix } = JSON.parse(db.get('config') as string)
const channel = member.guild.channels.get(welcomeChannel) as TextChannel
/////////////////////////////////////////////////////////////////////
if (!channel) return
Canvas.registerFont(path.join(__dirname, '..', 'core', 'images', 'GENUINE.ttf'), {
family: 'GENUINE'
})
const canvas = Canvas.createCanvas(800, 400)
const ctx = canvas.getContext('2d')
const background = await Canvas.loadImage(`${__dirname}/../core/images/welcome.png`)
ctx.drawImage(background, 0, 0, canvas.width + 2, canvas.height + 2)
ctx.strokeStyle = 'black'
ctx.strokeRect(0, 0, canvas.width, canvas.height)
// Greetings
ctx.font = '50px GENUINE'
ctx.fillStyle = '#dfdfdf'
ctx.fillText(`WELCOME:`, 20, 380)
// Username
ctx.font = '50px GENUINE'
ctx.fillStyle = '#a2ba00'
const textLength = member.user.username.length
ctx.fillText(member.user.username.toUpperCase(), 280 - textLength, 380)
ctx.strokeText(member.user.username.toUpperCase(), 280 - textLength, 380)
// Rules
ctx.font = '30px GENUINE'
ctx.fillStyle = '#dfdfdf'
ctx.fillText(`View our rules with [ ${prefix}rules ]`, 20, 280)
ctx.strokeText(`View our rules with [ ${prefix}rules ]`, 20, 280)
// Roles
ctx.font = '30px GENUINE'
ctx.fillStyle = '#dfdfdf'
ctx.fillText(`View our roles with [ ${prefix}roles ]`, 20, 310)
ctx.strokeText(`View our roles with [ ${prefix}roles ]`, 20, 310)
// Pick up the pen
ctx.beginPath()
// Start the arc to form a circle
ctx.arc(120, 120, 100, 0, Math.PI * 2)
// Put the pen down
ctx.closePath()
// Clip off the region you drew on
ctx.clip()
// Avatar
const avatar = await Canvas.loadImage(member.user.displayAvatarURL)
ctx.drawImage(avatar, 20, 20, 200, 200)
const attachment = new Attachment(canvas.toBuffer(), 'welcome-image.png')
channel.send(`Welcome home, ${member}!`, attachment)
}