Skip to content

Commit

Permalink
Add google command to google things for other people
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <daniel@shedaniel.me>
  • Loading branch information
shedaniel committed Feb 12, 2021
1 parent 5301da7 commit c43a909
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/me/shedaniel/linkie/discord/LinkieBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@ fun registerCommands(commands: CommandHandler) {
commands.registerCommand(TricksCommand, "trick")
commands.registerCommand(ValueCommand, "value")
commands.registerCommand(FabricCommand, "fabric")
commands.registerCommand(GoogleCommand, "google")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2019, 2020 shedaniel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package me.shedaniel.linkie.discord.commands

import discord4j.core.`object`.entity.User
import discord4j.core.`object`.entity.channel.MessageChannel
import discord4j.core.event.domain.message.MessageCreateEvent
import me.shedaniel.linkie.discord.CommandBase
import me.shedaniel.linkie.discord.MessageCreator
import me.shedaniel.linkie.discord.validateNotEmpty
import java.net.URLEncoder

object GoogleCommand : CommandBase {
override suspend fun execute(event: MessageCreateEvent, message: MessageCreator, prefix: String, user: User, cmd: String, args: MutableList<String>, channel: MessageChannel) {
args.validateNotEmpty(prefix, "$cmd <query>")
message.send("https://letmegooglethat.com/?q=" + args.joinToString(" ").escapeHTML()).subscribe()
}

private fun String.escapeHTML(): String {
return URLEncoder.encode(this, "UTF-8")
}
}

0 comments on commit c43a909

Please sign in to comment.