mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 10:19:10 +00:00
finish MVP
This commit is contained in:
parent
7806219464
commit
eaa1167f16
22 changed files with 486 additions and 116 deletions
|
@ -11,6 +11,7 @@ class DiscordService extends Service {
|
|||
this.clientSecret = process.env.DISCORD_CLIENT_SECRET
|
||||
this.oauthCallback = process.env.OAUTH_AUTH_CALLBACK
|
||||
this.botCallback = `${ctx.config.appUrl}/api/oauth/bot/callback`
|
||||
this.appUrl = process.env.APP_URL
|
||||
|
||||
this.client = new discord.Client()
|
||||
|
||||
|
@ -24,6 +25,8 @@ class DiscordService extends Service {
|
|||
async startBot () {
|
||||
await this.client.login(this.botToken)
|
||||
|
||||
this.client.on('message', this.handleMessage.bind(this))
|
||||
|
||||
for (let server of this.client.guilds.array()) {
|
||||
await this.ctx.server.ensure(server)
|
||||
}
|
||||
|
@ -127,6 +130,20 @@ class DiscordService extends Service {
|
|||
getBotJoinUrl () {
|
||||
return `https://discordapp.com/oauth2/authorize?client_id=${this.clientId}&scope=bot&permissions=268435456&redirect_uri=${this.botCallback}`
|
||||
}
|
||||
|
||||
mentionResponse (message) {
|
||||
message.channel.send(`🔰 Assign your roles here! <${this.appUrl}/s/${message.guild.id}>`, { disableEveryone: true })
|
||||
}
|
||||
|
||||
handleMessage (message) {
|
||||
if (message.author.bot && message.channel.type !== 'text') { // drop bot messages and dms
|
||||
return
|
||||
}
|
||||
|
||||
if (message.mentions.users.has(this.client.user.id)) {
|
||||
this.mentionResponse(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DiscordService
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue