-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added avatar command * Use List#isNotEmpty for args check
- Loading branch information
1 parent
b5d3006
commit 7d516a1
Showing
3 changed files
with
85 additions
and
15 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/kotlin/io/github/yuutoproject/yuutobot/commands/Avatar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.isNotEmpty()) { | ||
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/io/github/yuutoproject/yuutobot/utils/memberUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |