Add debug commands, start site
This commit is contained in:
parent
aa55c21f04
commit
d18280d4ca
|
@ -24,7 +24,9 @@ dependencies {
|
|||
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
|
||||
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.1'
|
||||
compile 'com.github.salomonbrys.kotson:kotson:2.5.0'
|
||||
compile 'io.javalin:javalin:2.1.1'
|
||||
compile "io.ktor:ktor-server-jetty:0.9.4"
|
||||
compile "io.ktor:ktor-freemarker:0.9.4"
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -46,3 +48,8 @@ jar {
|
|||
attributes 'Main-Class': 'nl.voidcorp.yeetbot.YeetKt'
|
||||
}
|
||||
}
|
||||
kotlin {
|
||||
experimental {
|
||||
coroutines "enable"
|
||||
}
|
||||
}
|
14
conf.json
14
conf.json
|
@ -5,7 +5,7 @@
|
|||
"list": [
|
||||
{
|
||||
"match": "fr0+d",
|
||||
"time": 1536955561058,
|
||||
"time": 1537026860849,
|
||||
"type": "REGEX"
|
||||
},
|
||||
{
|
||||
|
@ -15,15 +15,23 @@
|
|||
},
|
||||
{
|
||||
"match": "(me)+",
|
||||
"time": 1536955642192,
|
||||
"time": 1537026778635,
|
||||
"type": "REGEX"
|
||||
},
|
||||
{
|
||||
"match": "ye+t",
|
||||
"time": 1536955551512,
|
||||
"time": 1537033544530,
|
||||
"type": "REGEX"
|
||||
},
|
||||
{
|
||||
"match": "mems",
|
||||
"time": 1537026778640,
|
||||
"type": "RAW"
|
||||
}
|
||||
]
|
||||
},
|
||||
"313400918353772544": {
|
||||
"list": []
|
||||
}
|
||||
}
|
||||
}
|
58
src/main/kotlin/nl/voidcorp/yeetbot/CustomLogging.kt
Normal file
58
src/main/kotlin/nl/voidcorp/yeetbot/CustomLogging.kt
Normal file
|
@ -0,0 +1,58 @@
|
|||
package nl.voidcorp.yeetbot
|
||||
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import org.eclipse.jetty.util.log.Logger
|
||||
|
||||
class CustomLogging : Logger {
|
||||
val logger = LogManager.getLogger("JettyLog")
|
||||
|
||||
override fun getName(): String {
|
||||
return "JettyLog"
|
||||
}
|
||||
|
||||
override fun warn(msg: String, vararg args: Any) {
|
||||
logger.warn(msg, args)
|
||||
}
|
||||
|
||||
override fun warn(thrown: Throwable) {
|
||||
logger.warn(thrown)
|
||||
}
|
||||
override fun warn(msg: String, thrown: Throwable) {
|
||||
logger.warn(msg,thrown)
|
||||
}
|
||||
override fun info(msg: String, vararg args: Any) {
|
||||
logger.info(msg,args)
|
||||
}
|
||||
override fun info(thrown: Throwable) {
|
||||
logger.info(thrown)
|
||||
}
|
||||
override fun info(msg: String, thrown: Throwable) {
|
||||
logger.info(msg,thrown)
|
||||
}
|
||||
override fun isDebugEnabled(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun setDebugEnabled(enabled: Boolean) {
|
||||
|
||||
}
|
||||
override fun debug(msg: String, vararg args: Any) {
|
||||
logger.debug(msg,args)
|
||||
}
|
||||
override fun debug(thrown: Throwable) {
|
||||
logger.debug(thrown)
|
||||
}
|
||||
override fun debug(msg: String, thrown: Throwable) {
|
||||
logger.debug(msg,thrown)
|
||||
}
|
||||
override fun debug(msg: String?, value: Long) {
|
||||
logger.debug(msg,value)
|
||||
}
|
||||
override fun getLogger(name: String): Logger {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun ignore(ignored: Throwable) {
|
||||
logger.trace(ignored)
|
||||
}
|
||||
}
|
41
src/main/kotlin/nl/voidcorp/yeetbot/HTTP.kt
Normal file
41
src/main/kotlin/nl/voidcorp/yeetbot/HTTP.kt
Normal file
|
@ -0,0 +1,41 @@
|
|||
package nl.voidcorp.yeetbot
|
||||
|
||||
import freemarker.cache.FileTemplateLoader
|
||||
import io.ktor.application.ApplicationCall
|
||||
import io.ktor.application.call
|
||||
import io.ktor.application.install
|
||||
import io.ktor.freemarker.FreeMarker
|
||||
import io.ktor.freemarker.FreeMarkerContent
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.content.files
|
||||
import io.ktor.http.content.static
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.response.respondText
|
||||
import io.ktor.routing.get
|
||||
import io.ktor.routing.routing
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.jetty.Jetty
|
||||
import java.io.File
|
||||
|
||||
suspend fun ApplicationCall.respondJson(any: Any) = this.respondText(any.toJson(), contentType = ContentType.parse("application/json"))
|
||||
|
||||
fun server() {
|
||||
|
||||
val server = embeddedServer(Jetty, port = config.httpPort) {
|
||||
install(FreeMarker) {
|
||||
templateLoader = FileTemplateLoader(File("templates"))
|
||||
}
|
||||
|
||||
|
||||
routing {
|
||||
static {
|
||||
files("static")
|
||||
}
|
||||
get("/") {
|
||||
call.respond(FreeMarkerContent("index.ftl", mapOf("title" to "memes!")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server.start()
|
||||
}
|
|
@ -5,15 +5,20 @@ import net.dv8tion.jda.core.Permission
|
|||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter
|
||||
import net.dv8tion.jda.core.utils.PermissionUtil
|
||||
import java.io.FileWriter
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.util.regex.Pattern
|
||||
|
||||
|
||||
class MessageListener : ListenerAdapter() {
|
||||
val escapeEx = "[[\\p{Punct}&&[^:]]|\\s|#]*"
|
||||
|
||||
override fun onGuildMessageReceived(event: GuildMessageReceivedEvent) {
|
||||
if (event.author.isBot) return
|
||||
val msg = event.message.contentRaw
|
||||
val guild = event.guild
|
||||
if (PermissionUtil.checkPermission(event.member, Permission.ADMINISTRATOR) && msg.startsWith("%")) {
|
||||
println("User: ${event.author.name}#${event.author.discriminator}")
|
||||
if ((PermissionUtil.checkPermission(event.member, Permission.ADMINISTRATOR) || ((event.author.name == "J00LZ") && (event.author.discriminator == 9386.toString()))) && msg.startsWith("%")) {
|
||||
when {
|
||||
msg.substring(1).startsWith("addword ") -> {
|
||||
val m = msg.replace("%addword ", "").trim()
|
||||
|
@ -58,26 +63,52 @@ class MessageListener : ListenerAdapter() {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
msg.substring(1) == "debuginfo" -> {
|
||||
val f = FileWriter(guild.name)
|
||||
val me = guild.jda.selfUser
|
||||
val perms = PermissionUtil.getEffectivePermission(guild.getMember(me))
|
||||
for (p in Permission.getPermissions(perms)) {
|
||||
f.write("$p\n")
|
||||
}
|
||||
f.close()
|
||||
}
|
||||
}
|
||||
|
||||
} else if (!event.author.isBot) {
|
||||
val map = config.guildWords.getOrPut(guild.idLong) { GuildInfo() }.list
|
||||
for (match in map) {
|
||||
/*logger.info("Does `$msg` match `${"$escapeEx${match.match}$escapeEx"}`: ${Pattern.compile("$escapeEx${match.match}$escapeEx").matcher(msg).find()}")*/
|
||||
if ((Pattern.matches("$escapeEx${match.match}$escapeEx", msg.toLowerCase()))) {
|
||||
|
||||
/*if (msg.indexOf(match.match) - 1 > 0 && ((msg[msg.indexOf(match.match) - 1] != ' ') ||
|
||||
Pattern.matches("[\\p{Punct}&&[^:]]+", msg[msg.indexOf(match.match) - 1].toString()))) {
|
||||
println("meme")
|
||||
return
|
||||
} else if (msg.indexOf(match.match) + match.match.length + 1 <= msg.length && ((msg[msg.indexOf(match.match) + match.match.length + 1] != ' ') ||
|
||||
Pattern.matches("[\\p{Punct}&&[^:]]+", msg[msg.indexOf(match.match) + match.match.length + 1].toString()))) {
|
||||
println("mama")
|
||||
return
|
||||
}*/
|
||||
|
||||
|
||||
if ((match.type == MatchType.RAW && msg.contains(match.match))) {
|
||||
if (match.time <= System.currentTimeMillis()) {
|
||||
val past = Instant.ofEpochMilli(match.time)
|
||||
val now = Instant.ofEpochMilli(System.currentTimeMillis())
|
||||
val time = Duration.between(past, now)
|
||||
|
||||
val txt = match.match.toRegex().toPattern().matcher(msg)
|
||||
/*if (txt.regionStart() > 1 && txt.regionEnd() + 1 < msg.length) {
|
||||
if (txt.reg)
|
||||
}*/
|
||||
match.time = now.toEpochMilli() + 1000 * 60 * 30
|
||||
event.channel.sendMessage(MessageBuilder().append(event.member)
|
||||
.append(" said the forbidden word `").append(match.match)
|
||||
.append(" said the forbidden word `").append(msg.substring(txt.regionStart(), txt.regionEnd()))
|
||||
.append("`! \nI have reset the counter for this word and will wait 30 minutes so you can spam it as much as you want. \nYou lived ")
|
||||
.append("${time.toDays()} days ${time.toHours() % 24} hours ${time.toMinutes() % 60} minutes and ${(time.toMillis() / 1000) % 60} seconds")
|
||||
.append(" without mentioning it.").build()).queue()
|
||||
}
|
||||
} else if (match.type == MatchType.REGEX && msg.contains(match.match.toRegex())) {
|
||||
} /*else if (match.type == MatchType.REGEX && msg.contains(match.match.toRegex())) {
|
||||
if (match.time <= System.currentTimeMillis()) {
|
||||
val past = Instant.ofEpochMilli(match.time)
|
||||
val now = Instant.ofEpochMilli(System.currentTimeMillis())
|
||||
|
@ -86,7 +117,9 @@ class MessageListener : ListenerAdapter() {
|
|||
logger.info(msg.contains(match.match.toRegex()))
|
||||
logger.info(match.match.toRegex().toPattern().matcher(msg).find())
|
||||
val txt = match.match.toRegex().toPattern().matcher(msg)
|
||||
|
||||
*//*if (txt.regionStart() > 1 && txt.regionEnd() + 1 < msg.length) {
|
||||
if (txt.reg)
|
||||
}*//*
|
||||
match.time = now.toEpochMilli() + 1000 * 60 * 30
|
||||
event.channel.sendMessage(MessageBuilder().append(event.member)
|
||||
.append(" said the forbidden word `").append(msg.substring(txt.regionStart(), txt.regionEnd()))
|
||||
|
@ -94,7 +127,7 @@ class MessageListener : ListenerAdapter() {
|
|||
.append("${time.toDays()} days ${time.toHours() % 24} hours ${time.toMinutes() % 60} minutes and ${(time.toMillis() / 1000) % 60} seconds")
|
||||
.append(" without mentioning it.").build()).queue()
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package nl.voidcorp.yeetbot
|
||||
|
||||
import com.github.salomonbrys.kotson.fromJson
|
||||
import io.javalin.Javalin
|
||||
import io.javalin.json.FromJsonMapper
|
||||
import io.javalin.json.JavalinJson
|
||||
import io.javalin.json.ToJsonMapper
|
||||
import net.dv8tion.jda.core.AccountType
|
||||
import net.dv8tion.jda.core.JDABuilder
|
||||
import net.dv8tion.jda.core.OnlineStatus
|
||||
|
@ -19,7 +15,7 @@ import kotlin.concurrent.schedule
|
|||
|
||||
|
||||
lateinit var config: Config
|
||||
val logger = LogManager.getLogger("YeetBot")
|
||||
val logger = LogManager.getLogger("YeetBot")!!
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
|
@ -87,23 +83,12 @@ fun main(args: Array<String>) {
|
|||
}
|
||||
}
|
||||
|
||||
JavalinJson.toJsonMapper = object : ToJsonMapper {
|
||||
override fun map(obj: Any): String = obj.toJson()
|
||||
}
|
||||
org.eclipse.jetty.util.log.Log.setLog(CustomLogging())
|
||||
|
||||
server()
|
||||
|
||||
|
||||
JavalinJson.fromJsonMapper = object : FromJsonMapper {
|
||||
override fun <T> map(json: String, targetClass: Class<T>): T = gson.fromJson(json, targetClass)
|
||||
|
||||
}
|
||||
|
||||
val app = Javalin.create().start(config.httpPort)
|
||||
app.get("/") {
|
||||
it.result("memes!")
|
||||
}
|
||||
|
||||
app.get("/test") {
|
||||
it.json(config)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
122
static/css/style.css
Normal file
122
static/css/style.css
Normal file
|
@ -0,0 +1,122 @@
|
|||
|
||||
.title {
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.login {
|
||||
|
||||
padding: 10px 10px 10px 10px;
|
||||
margin: 5px auto;
|
||||
width: 320px;
|
||||
text-align: center;
|
||||
background-color: white;
|
||||
border-radius: 10px;
|
||||
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
transform-origin: 0 0;
|
||||
}
|
||||
|
||||
.loginadd {
|
||||
animation: createBox .75s;
|
||||
|
||||
}
|
||||
|
||||
label {
|
||||
display: inline-block;
|
||||
width: 100px;
|
||||
margin-right: 30px;
|
||||
margin-bottom: 5px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
input {
|
||||
font-family: 'Raleway', sans-serif;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
}
|
||||
|
||||
.button {
|
||||
font-family: 'Raleway', sans-serif;
|
||||
padding: 5px 30px;
|
||||
margin-top: 8px;
|
||||
border: 0;
|
||||
background: dimgrey;
|
||||
box-shadow: none;
|
||||
border-radius: 5px;
|
||||
color: #fff;
|
||||
font-size: 1em;
|
||||
text-underline-mode: none;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background: #545454;
|
||||
}
|
||||
|
||||
.warn:hover {
|
||||
background: orangered;
|
||||
}
|
||||
|
||||
.home:hover {
|
||||
background: darkblue;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Raleway', sans-serif;
|
||||
background: black /*url("/images/bg.gif")*/ no-repeat fixed center;
|
||||
}
|
||||
|
||||
.center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.links {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.link:visited {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.link {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
color: #505050;
|
||||
}
|
||||
|
||||
.frm {
|
||||
margin-top: 19px;
|
||||
}
|
||||
|
||||
h4 {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
@keyframes createBox {
|
||||
from {
|
||||
transform: scale(0) translate(-50%, -50%);
|
||||
}
|
||||
to {
|
||||
transform: scale(1) translate(-50%, -50%);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes destroyBox {
|
||||
from {
|
||||
transform: scale(1) translate(-50%, -50%);
|
||||
}
|
||||
to {
|
||||
transform: scale(0) translate(-50%, -50%);
|
||||
}
|
||||
}
|
||||
|
BIN
static/images/bg.gif
Normal file
BIN
static/images/bg.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 402 KiB |
18
templates/index.ftl
Normal file
18
templates/index.ftl
Normal file
|
@ -0,0 +1,18 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>${title}</title>
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Raleway" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="css/style.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="login">
|
||||
<h1 class="title">${title}</h1>
|
||||
<a class="button warn" href="https://google.com/">Google</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue