Skip to content
Snippets Groups Projects
Verified Commit 9f20e53b authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Prepare for cleanly executing expansions

parent ab835591
No related merge requests found
......@@ -16,9 +16,11 @@ import de.justjanne.libquassel.protocol.models.Command
import de.justjanne.libquassel.protocol.models.QStringList
import de.justjanne.libquassel.protocol.models.types.QtType
import de.justjanne.libquassel.protocol.syncables.stubs.AliasManagerStub
import de.justjanne.libquassel.protocol.util.expansion.Expansion
import de.justjanne.libquassel.protocol.variant.QVariantMap
import de.justjanne.libquassel.protocol.variant.into
import de.justjanne.libquassel.protocol.variant.qVariant
import kotlin.math.exp
class AliasManager constructor(
session: Session
......@@ -90,9 +92,28 @@ class AliasManager constructor(
fun expand(
expansion: String,
bufferInfo: BufferInfo,
msg: String,
arguments: String,
previousCommands: MutableList<Command>
) {
/*
val params = arguments.split(' ')
expansion.split(';')
.map(String::trimStart)
.map(Expansion.Companion::parse)
.map {
it.map {
when (it) {
is Expansion.Constant -> TODO()
is Expansion.Parameter -> TODO()
is Expansion.ParameterRange ->
params.subList(it.from, it.to ?: params.size)
.joinToString(" ")
is Expansion.Text ->
it.value
}
}
}
*/
}
fun copy() = AliasManager(session).also {
......
......@@ -10,26 +10,126 @@
package de.justjanne.libquassel.protocol.util.expansion
/**
* Model for a command expansion
*/
sealed class Expansion {
data class Text(val value: String) : Expansion()
data class ParameterRange(val from: Int, val to: Int?) : Expansion()
data class Parameter(val index: Int, val field: ParameterField?) : Expansion()
data class Constant(val field: ConstantField) : Expansion()
/**
* Model for raw text
*/
data class Text(
/**
* Text to insert
*/
val value: String
) : Expansion()
/**
* Model for a parameter range
*/
data class ParameterRange(
/**
* Index of the first included parameter.
*/
val from: Int,
/**
* Index of the last included parameter.
* If null, this means all parameters after the start should be included
*/
val to: Int?
) : Expansion()
/**
* Model for a single parameter
*/
data class Parameter(
/**
* Index of the parameter
*/
val index: Int,
/**
* Attribute of the parameter to access, if possible.
*
* If null, this just inserts the value of the nth parameter itself.
* Otherwise this causes a lookup of the specified value.
*
* If e.g. the nth value is "justjanne", and this field is set to
* [ParameterField.VERIFIED_IDENT], it’ll look up the ident of justjanne
* in the current context, try to verify it, and set it to * otherwise.
*/
val field: ParameterField?
) : Expansion()
/**
* Model for a single constant in the current context
*/
data class Constant(
/**
* Type of constant to be inserted
*/
val field: ConstantField
) : Expansion()
/**
* Potential fields that can be specified on a given parameter
*/
enum class ParameterField {
/**
* Hostname of the ircuser with the specified nick on the network of the
* given context, or "*" if the user is not found or the hostname could not
* be determined.
*/
HOSTNAME,
/**
* Ident of the ircuser with the specified nick on the network of the
* given context.
*
* Will be set to "*" if the ident is not verified (prefixed with ~), the
* user is not found or the ident could not be determined.
*/
VERIFIED_IDENT,
/**
* Ident of the ircuser with the specified nick on the network of the
* given context, or "*" if the user is not found or the hostname could not
* be determined.
*/
IDENT,
/**
* Account of the ircuser with the specified nick on the network of the
* given context, or "*" if the user is not found or the hostname could not
* be determined.
*/
ACCOUNT
}
/**
* Potential fields that can be specified on a given context
*/
enum class ConstantField {
/**
* Name of the current IRC channel, otherwise the name of the current chat
* if the alias is invoked outside of a channel
*/
CHANNEL,
/**
* Nick of the user invoking this alias
*/
NICK,
/**
* Name of the network this alias is invoked on
*/
NETWORK
}
companion object {
/**
* Parse a list of expansions from a given expansion string
*/
fun parse(text: String): List<Expansion> =
ExpansionParsingContext(text).parse()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment