-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
LilyBot.kt
157 lines (140 loc) · 5.38 KB
/
LilyBot.kt
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
@file:OptIn(PrivilegedIntent::class)
package org.hyacinthbots.lilybot
import com.kotlindiscord.kord.extensions.ExtensibleBot
import com.kotlindiscord.kord.extensions.checks.hasPermission
import com.kotlindiscord.kord.extensions.modules.extra.phishing.DetectionAction
import com.kotlindiscord.kord.extensions.modules.extra.phishing.extPhishing
import com.kotlindiscord.kord.extensions.modules.extra.pluralkit.extPluralKit
import dev.kord.common.entity.Permission
import dev.kord.gateway.Intent
import dev.kord.gateway.PrivilegedIntent
import io.github.oshai.kotlinlogging.KotlinLogging
import org.hyacinthbots.docgenerator.docsGenerator
import org.hyacinthbots.docgenerator.enums.CommandTypes
import org.hyacinthbots.docgenerator.enums.SupportedFileFormat
import org.hyacinthbots.lilybot.database.collections.WelcomeChannelCollection
import org.hyacinthbots.lilybot.database.storage.MongoDBDataAdapter
import org.hyacinthbots.lilybot.extensions.config.Config
import org.hyacinthbots.lilybot.extensions.config.ConfigOptions
import org.hyacinthbots.lilybot.extensions.config.GuildLogging
import org.hyacinthbots.lilybot.extensions.events.AutoThreading
import org.hyacinthbots.lilybot.extensions.events.MemberLogging
import org.hyacinthbots.lilybot.extensions.events.MessageDelete
import org.hyacinthbots.lilybot.extensions.events.MessageEdit
import org.hyacinthbots.lilybot.extensions.events.ModThreadInviting
import org.hyacinthbots.lilybot.extensions.moderation.LockingCommands
import org.hyacinthbots.lilybot.extensions.moderation.ModerationCommands
import org.hyacinthbots.lilybot.extensions.moderation.Report
import org.hyacinthbots.lilybot.extensions.util.GalleryChannel
import org.hyacinthbots.lilybot.extensions.util.Github
import org.hyacinthbots.lilybot.extensions.util.GuildAnnouncements
import org.hyacinthbots.lilybot.extensions.util.InfoCommands
import org.hyacinthbots.lilybot.extensions.util.ModUtilities
import org.hyacinthbots.lilybot.extensions.util.NewsChannelPublishing
import org.hyacinthbots.lilybot.extensions.util.PublicUtilities
import org.hyacinthbots.lilybot.extensions.util.Reminders
import org.hyacinthbots.lilybot.extensions.util.RoleMenu
import org.hyacinthbots.lilybot.extensions.util.StartupHooks
import org.hyacinthbots.lilybot.extensions.util.StatusPing
import org.hyacinthbots.lilybot.extensions.util.Tags
import org.hyacinthbots.lilybot.extensions.util.ThreadControl
import org.hyacinthbots.lilybot.utils.BOT_TOKEN
import org.hyacinthbots.lilybot.utils.ENVIRONMENT
import org.hyacinthbots.lilybot.utils.SENTRY_DSN
import org.hyacinthbots.lilybot.utils.database
import org.hyacinthbots.lilybot.utils.getLoggingChannelWithPerms
import org.kohsuke.github.GitHub
import org.kohsuke.github.GitHubBuilder
import org.quiltmc.community.cozy.modules.welcome.welcomeChannel
import java.io.IOException
import kotlin.io.path.Path
import kotlin.time.Duration.Companion.minutes
lateinit var github: GitHub
private val gitHubLogger = KotlinLogging.logger("GitHub Logger")
val docFile = Path("./docs/commands.md")
suspend fun main() {
val bot = ExtensibleBot(BOT_TOKEN) {
database(true)
dataAdapter(::MongoDBDataAdapter)
members {
lockMemberRequests = true // Collect members one at a time to avoid hitting rate limits
all()
}
// Enable the members intent to allow us to get accurate member counts for join logging
intents {
+Intent.GuildMembers
}
// Add the extensions to the bot
extensions {
add(::AutoThreading)
add(::Config)
add(::GalleryChannel)
add(::Github)
add(::GuildAnnouncements)
add(::GuildLogging)
add(::InfoCommands)
add(::LockingCommands)
add(::MemberLogging)
add(::MessageDelete)
add(::MessageEdit)
add(::ModThreadInviting)
add(::ModUtilities)
add(::ModerationCommands)
add(::NewsChannelPublishing)
add(::PublicUtilities)
add(::Reminders)
add(::Report)
add(::RoleMenu)
add(::StartupHooks)
add(::StatusPing)
add(::Tags)
add(::ThreadControl)
/*
The welcome channel extension allows users to designate a YAML file to create a channel with
a variety of pre-built blocks.
*/
welcomeChannel(WelcomeChannelCollection()) {
staffCommandCheck {
hasPermission(Permission.BanMembers)
}
getLogChannel { _, guild ->
getLoggingChannelWithPerms(ConfigOptions.UTILITY_LOG, guild)
}
refreshDuration = 5.minutes
}
/*
The anti-phishing extension automatically deletes and logs scam links. It also allows users to check links
with a command. It kicks users who send scam links, rather than ban, to allow them to rejoin if they regain
control of their account
*/
extPhishing {
appName = "Lily Bot"
detectionAction = DetectionAction.Kick
logChannelName = "anti-phishing-logs"
requiredCommandPermission = null
}
extPluralKit()
sentry {
enableIfDSN(SENTRY_DSN) // Use the nullable sentry function to allow the bot to be used without a DSN
}
}
docsGenerator {
enabled = true
fileFormat = SupportedFileFormat.MARKDOWN
commandTypes = CommandTypes.ALL
filePath = docFile
environment = ENVIRONMENT
useBuiltinCommandList = true
botName = "LilyBot"
}
// Connect to GitHub to allow the GitHub commands to function
try {
github = GitHubBuilder().build()
gitHubLogger.info { "Connected to GitHub!" }
} catch (exception: IOException) {
exception.printStackTrace()
gitHubLogger.error { "Failed to connect to GitHub!" }
}
}
bot.start()
}