Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Avatar command #19

Merged
merged 2 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/main/kotlin/io/github/yuutoproject/yuutobot/commands/Avatar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Open source bot built by and for the Camp Buddy Discord Fan Server.
* Copyright (C) 2020 Kyuuto-devs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.yuutoproject.yuutobot.commands

import io.github.yuutoproject.yuutobot.commands.base.AbstractCommand
import io.github.yuutoproject.yuutobot.commands.base.CommandCategory
import io.github.yuutoproject.yuutobot.utils.findMember
import net.dv8tion.jda.api.entities.User
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent

class Avatar : AbstractCommand(
"avatar",
CommandCategory.UTIL,
"Gets your own or someone's avatar",
"avatar or avatar <user>"
) {
override fun run(args: MutableList<String>, event: GuildMessageReceivedEvent) {
var user: User? = event.author

if (args.size != 0) {
MorphTuple marked this conversation as resolved.
Show resolved Hide resolved
user = findMember(args.joinToString(" "), event)?.user
}

if (user == null) {
event.channel.sendMessage("${event.author.asMention} Sorry, but I can't find that user").queue()
return
}

event.channel.sendMessage("${event.author.asMention}, Here ya go~!\n" + user.effectiveAvatarUrl + "?size=2048").queue()
}
}
18 changes: 3 additions & 15 deletions src/main/kotlin/io/github/yuutoproject/yuutobot/commands/Ship.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

package io.github.yuutoproject.yuutobot.commands

import com.jagrosh.jdautilities.commons.utils.FinderUtil
import io.github.yuutoproject.yuutobot.commands.base.AbstractCommand
import io.github.yuutoproject.yuutobot.commands.base.CommandCategory
import io.github.yuutoproject.yuutobot.extensions.getStaticAvatarUrl
import io.github.yuutoproject.yuutobot.utils.Constants
import io.github.yuutoproject.yuutobot.utils.findMember
import io.github.yuutoproject.yuutobot.utils.httpClient
import io.github.yuutoproject.yuutobot.utils.jackson
import java.io.File
Expand Down Expand Up @@ -73,15 +73,15 @@ class Ship : AbstractCommand(
}

val name1 = args[0]
val member1 = this.findMember(name1, event)
val member1 = findMember(name1, event)

if (member1 == null) {
channel.sendMessage("No user found for input $name1").queue()
return
}

val name2 = args[1]
val member2 = this.findMember(name2, event)
val member2 = findMember(name2, event)

if (member2 == null) {
channel.sendMessage("No user found for input $name2").queue()
Expand Down Expand Up @@ -112,18 +112,6 @@ class Ship : AbstractCommand(
}
}

private fun findMember(input: String, event: GuildMessageReceivedEvent): Member? {
val foundMembers = FinderUtil.findMembers(input, event.guild)

if (foundMembers.isEmpty()) {
return null
}

// why not "?: null"
// Well java is fun and will throw an index out of bounds exception if there is no first element
return foundMembers[0]
}

private fun shouldBeRigged(member1: Member, member2: Member): Boolean {
val id1 = member1.idLong
val id2 = member2.idLong
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Open source bot built by and for the Camp Buddy Discord Fan Server.
* Copyright (C) 2020 Kyuuto-devs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.yuutoproject.yuutobot.utils

import com.jagrosh.jdautilities.commons.utils.FinderUtil
import net.dv8tion.jda.api.entities.Member
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent

fun findMember(input: String, event: GuildMessageReceivedEvent): Member? {
val foundMembers = FinderUtil.findMembers(input, event.guild)

if (foundMembers.isEmpty()) {
return null
}

// why not "?: null"
// Well java is fun and will throw an index out of bounds exception if there is no first element
return foundMembers[0]
}