Command framework built around Kord, built to be robust and scalable, following Kord's convention and design patterns.

Overview

GitHub Workflow Status (branch) Discord

KFox

While using Kord, have you ever stopped and thought to yourself; "I wonder how I could add a command that adds a button that shows a fox whenever I want." Well dear user, I have! To solve this problem I, Amy (ya queen, ya girl), decided to create a library that will let you create commands, components and other Discord interactions easily, quickly and effortlessly.

Meme over, serious only now

KFox is a Discord interaction library written in Kotlin built on-top of Kord. It will allow you to easily create and respond to any type of interaction that Kord (and by extension Discord) supports.

Supported interactions

  • Commands
    • Parameters
    • Sub-commands
    • Groups
    • User commands
    • Message commands
    • Autocomplete
    • Localization
  • Buttons
  • Select menus
  • Modals

Installation

TODO

Examples

⚠️ KFox currently does not support automatically creating your commands on the Discord side of things.

With every type of interaction you will receive either a CommandContext or ComponentContext, these context objects contain a variety of things like the Kord instance, the event and the response. For every type of context there exists a Public and Ephemeral variant, depending on which one you request in your callback functions the interaction will be handled as ephemeral, meaning that only the user who triggered the interaction can see the reply, or public. All the examples below use the Public variant, you are free to change these to Ephemeral as you please of course.

Setup and commands

Setting up KFox is as easy as calling a single extension function on your Kord instance.

suspend fun main() {
    val kord = Kord("your_token_here")
    kord.listen() // 1
    kord.login()
}
  1. Ensure you call Kord#listen before you call Kord#login.

Creating a command

@Command("parrot", "I'm a friendly parakeet, I'll repeat what you said awk!") // 1
suspend fun testCommand(
    context: PublicChatCommandContext, // 2
    @Parameter("content", "content-key") // 3
    value: String
) = with(context) {
    response.createPublicFollowup {
        content = "Hi, I'm a friendly parakeet! You said \"$value,\" awk!"
    }
}
  1. Define a new function and annotate it with @Command.
  2. Hook in your context; ephemeral responses use EphemeralChatCommandContext, whereas public responses use PublicChatCommandContext.
  3. Define your parameters and annotate them with @Parameter.

Creating a sub-command (with a group)

@Command("parakeet", "A happy lil description.") // 1
@SubCommand("birds", "secret") // 2 & 3
suspend fun subCommandWithCategory(
    context: PublicChatCommandContext
) = with(context) {
    response.createPublicFollowup {
        content = "It looks like you found my cozy hideout, awk!"
    }
}
  1. Annotate your callback function with @Command, the name will be the name of the sub-command.
  2. Annotate it with @SubCommand, set the parent to the command we just created "parrot".
  3. Simply fill in the group with something to add this sub-command to a group, leave blank otherwise.

Components

All components need to be registered with the ComponentRegistry, the default implementation is an in-memory register, this means that your components do not persist between restarts. Should you need such functionality, implement the interface and store the IDs persistently. You can then pass an instance of your custom implementation in your Kord#listen call.

Buttons

const val CALLBACK_ID = "unique_callback_id"

@Button(CALLBACK_ID) // 1
suspend fun testButton(
    context: PublicButtonContext
) = with(context) {
    response.createPublicFollowup {
        content = "Awk!"
    }
}

@Command("parakeetbutton", "Press the button, awk?") // 2
suspend fun testCommand(
    context: PublicChatCommandContext,
) = with(context) {
    response.createPublicFollowup {
        actionRow {
            interactionButton(ButtonStyle.Primary, "my_custom_button_id") {
                label = "Awk?"

                register(CALLBACK_ID) // 3
            }
        }
    }
}
  1. Define a new function and annotate it with @Button, make sure the ID you specify is unique as this will be used internally to find and call this callback.
  2. Note that you do not necessarily need to create a new command to use buttons, but we do here for convenience.
  3. You must call register within components, this will inform KFox that this is a component we need to track and will create the link between this button and the callback function.

Select menus

const val MENU_CALLBACK = "unique_callback_id_2"

@SelectMenu(MENU_CALLBACK) // 1
suspend fun testMenu(
    context: PublicSelectMenuContext
) = with(context) {
    response.createPublicFollowup {
        content = "You picked \"${event.interaction.values.first()}\"! Awk!"
    }
}

@Command("parrotpick", "Pick whichever suits you most, awk!")
suspend fun testCommand(
    context: PublicChatCommandContext
) = with(context) {
    response.createPublicFollowup {
        actionRow {
            selectMenu("your_menu_id") {
                placeholder = "Select your favourite animal!"
                option("Foxes", "foxes")
                option("Bunnies", "bunnies")
                option("Cats", "cats")
                option("Dogs", "dogs")

                register(MENU_CALLBACK) // 2
            }
        }
    }
}
  1. Define a new function and annotate it with @Button, make sure the ID you specify is unique as this will be used internally to find and call this callback.
  2. You must call register within components, this will inform KFox that this is a component we need to track and will create the link between this button and the callback function.
You might also like...
A tiny framework to execute shell scripts on Android

Skippy A tiny framework to execute shell scripts on Android Why I first sought out to create a basic script manager for Android.

Same as the Outlined text fields presented on the Material Design page but with some dynamic changes. πŸ“ πŸŽ‰
Same as the Outlined text fields presented on the Material Design page but with some dynamic changes. πŸ“ πŸŽ‰

README SSCustomEditTextOutlineBorder Getting Started SSCustomEditTextOutLineBorder is a small kotlin library for android to support outlined (stroked)

An extension to the built in Android Battery Saver

Buoy An extension to the built in Android Battery Saver Description The built-in Android battery saver mode is actually quite powerful. The only disap

gRPC and protocol buffers for Android, Kotlin, and Java.

Wire β€œA man got to have a code!” - Omar Little See the project website for documentation and APIs. As our teams and programs grow, the variety and vol

General purpose utilities and hash functions for Android and Java (aka java-common)

Essentials Essentials are a collection of general-purpose classes we found useful in many occasions. Beats standard Java API performance, e.g. LongHas

Access and process various types of personal data in Android with a set of easy, uniform, and privacy-friendly APIs.
Access and process various types of personal data in Android with a set of easy, uniform, and privacy-friendly APIs.

PrivacyStreams PrivacyStreams is an Android library for easy and privacy-friendly personal data access and processing. It offers a functional programm

A library for fast and safe delivery of parameters for Activities and Fragments.

MorbidMask - 吸葀青具 Read this in other languages: δΈ­ζ–‡, English, Change Log A library for fast and safe delivery of parameters for Activities and Fragment

A simple and easy to use stopwatch and timer library for android

TimeIt Now with Timer support! A simple and easy to use stopwatch and timer library for android Introduction A stopwatch can be a very important widge

Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.

Trail Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platfor

Owner
ZeroTwo Bot
Github Repository for the Discord bot "ZeroTwo"
ZeroTwo Bot
Scalable vector graphics for Android

Sharp Sharp is a Scalable Vector Graphics (SVG) implementation for Android. It facilitates loading vector graphics as SharpDrawables, and can effectiv

Pixplicity 1k Dec 31, 2022
Small Android library to help you incorporate MVP, Passive View and Presentation Model patterns in your app

DroidMVP About DroidMVP is a small Android library to help you incorporate the MVP pattern along with Passive View and Presentation Model (yes, those

Andrzej Chmielewski 225 Nov 29, 2022
Wrapper around the android Camera class that simplifies its usage

EasyCamera Wrapper around the android Camera class that simplifies its usage (read more about the process) Usage: // the surface where the preview wil

Bozhidar Bozhanov 641 Dec 29, 2022
Handy library to send & receive command with payload between subscribers for Android.

Commander Handy library to send & receive command with payload between subscribers for Android. Features Subscription based No dependency on Framework

Romman Sabbir 3 Oct 19, 2021
A command line tool for NFT stuff

MartaKli is a command line tool to help you generate your NFT pfp project. Current features: Generate batch of images using different layers and corre

Martabak Cult 2 Oct 4, 2022
KDoctor - A command-line tool that helps to set up the environment for Kotlin Multiplatform Mobile app development

KDoctor is a command-line tool that helps to set up the environment for Kotlin Multiplatform Mobile app development.

Kotlin 331 Dec 29, 2022
Small command-line utility to safely merge multiple WhatsApp backups (msgstore.db) into one.

whatsapp-database-merger A small command-line utility that can be used to merge multiple WhatsApp databases (msgstore.db) into one. A few notes: input

Mattia Iavarone 31 Dec 27, 2022
A command line utility to help you investigate the sensitive data associated with Macie findings.

Macie Finding Data Reveal This project contains a command line utility to help you investigate the sensitive data associated with Macie findings.

AWS Samples 8 Nov 16, 2022
Gesture detector framework for multitouch handling on Android, based on Android's ScaleGestureDetector

Android Gesture Detectors Framework Introduction Since I was amazed Android has a ScaleGestureDetector since API level 8 but (still) no such thing as

null 1.1k Nov 30, 2022
Consumer android from nutrition-framework API

About This Project (work-in-progress ?? ??️ ??‍♀️ ⛏ ) Consumer Dari Nutrition Framework General Framework for Application Development Around Nutrition

Faisal Amir 0 Feb 24, 2022