Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
QuasselDroid-ng
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
QuasselDroid-ng
Commits
2acc2c65
Commit
2acc2c65
authored
7 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Fix alias expansion
parent
d5990794
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/src/main/java/de/kuschku/libquassel/quassel/syncables/AliasManager.kt
+20
-22
20 additions, 22 deletions
...a/de/kuschku/libquassel/quassel/syncables/AliasManager.kt
with
20 additions
and
22 deletions
lib/src/main/java/de/kuschku/libquassel/quassel/syncables/AliasManager.kt
+
20
−
22
View file @
2acc2c65
...
...
@@ -10,7 +10,6 @@ import de.kuschku.libquassel.quassel.syncables.interfaces.IAliasManager.Alias
import
de.kuschku.libquassel.quassel.syncables.interfaces.ISyncableObject
import
de.kuschku.libquassel.session.SignalProxy
import
java.util.*
import
java.util.regex.Pattern
class
AliasManager
constructor
(
proxy
:
SignalProxy
...
...
@@ -89,11 +88,13 @@ class AliasManager constructor(
}
else
{
// check for aliases
val
split
=
msg
.
split
(
' '
,
ignoreCase
=
true
,
limit
=
2
)
val
search
:
String
?
=
split
.
firstOrNull
()
val
search
:
String
?
=
split
.
firstOrNull
()
?.
substring
(
1
)
if
(
search
!=
null
)
{
val
found
=
_aliases
.
firstOrNull
{
it
.
name
.
equals
(
search
,
true
)
}
if
(
found
!=
null
)
if
(
found
!=
null
)
{
expand
(
found
.
expansion
,
info
,
split
.
getOrNull
(
1
)
?:
""
,
previousCommands
)
return
}
}
}
...
...
@@ -104,43 +105,40 @@ class AliasManager constructor(
previousCommands
:
MutableList
<
IAliasManager
.
Command
>)
{
val
network
=
proxy
.
network
(
bufferInfo
.
networkId
)
val
paramRange
=
Pattern
.
compile
(
"""\$(\d+)\.\.(\d*)"""
)
val
commands
=
Arrays
.
asList
(
*
expansion
.
split
(
"; ?"
).
dropLastWhile
{
it
.
isEmpty
()
}.
toTypedArray
()
)
val
params
=
Arrays
.
asList
<
String
>(
*
msg
.
split
(
' '
).
dropLastWhile
({
it
.
isEmpty
()
}).
toTypedArray
()
)
val
paramRange
=
Regex
(
"""\$(\d+)\.\.(\d*)"""
)
val
commands
=
expansion
.
split
(
"; ?"
.
toRegex
()).
dropLastWhile
{
it
.
isEmpty
()
}
val
params
=
msg
.
split
(
' '
).
dropLastWhile
({
it
.
isEmpty
()
})
val
expandedCommands
=
LinkedList
<
String
>()
for
(
i
in
commands
.
indices
)
{
var
command
=
commands
[
i
]
if
(
params
.
size
!=
0
)
{
val
m
=
paramRange
.
matcher
(
command
)
while
(
m
.
find
())
{
val
start
=
m
.
group
(
1
).
toIntOrNull
()
?:
-
1
if
(
params
.
isNotEmpty
())
{
for
(
match
in
paramRange
.
findAll
(
command
))
{
val
start
=
match
.
groups
[
1
]
?.
value
?.
toIntOrNull
()
?:
-
1
val
replacement
:
String
// $1.. would be "arg1 and all following"
replacement
=
if
(
m
.
group
(
2
).
is
Empty
())
{
replacement
=
if
(
m
atch
.
group
s
[
2
]
?.
value
.
isNullOr
Empty
())
{
params
.
subList
(
start
,
params
.
size
).
joinToString
(
" "
)
}
else
{
val
end
=
m
.
group
(
2
)
.
toIntOrNull
()
?:
-
1
val
end
=
m
atch
.
group
s
[
2
]
?.
value
?
.
toIntOrNull
()
?:
-
1
if
(
end
<
start
)
{
""
}
else
{
params
.
subList
(
start
,
end
).
joinToString
(
" "
)
}
}
command
=
command
.
substring
(
0
,
m
.
start
())
+
replacement
+
command
.
substring
(
m
.
end
())
command
=
command
.
substring
(
0
,
match
.
range
.
start
)
+
replacement
+
command
.
substring
(
match
.
range
.
endInclusive
+
1
)
}
}
for
(
j
in
params
.
size
downTo
1
)
{
val
user
=
network
?.
ircUser
(
params
[
j
-
1
])
val
host
=
user
?.
host
()
?:
"*"
command
=
command
.
replace
(
String
.
format
(
Locale
.
US
,
"$%d:hostname"
,
j
).
toRegex
(),
host
)
command
=
command
.
replace
(
String
.
format
(
Locale
.
US
,
"$%d"
,
j
).
toRegex
(),
params
[
j
-
1
])
command
=
command
.
replace
(
"\$$j:hostname"
,
user
?.
host
()
?:
"*"
)
command
=
command
.
replace
(
"\$$j:ident"
,
user
?.
user
()
?:
"*"
)
command
=
command
.
replace
(
"\$$j:account"
,
user
?.
account
()
?:
"*"
)
command
=
command
.
replace
(
"\$$j"
,
params
[
j
-
1
])
}
command
=
command
.
replace
(
"$0"
,
msg
)
command
=
command
.
replace
(
"\$channelname"
,
bufferInfo
.
bufferName
?:
""
)
...
...
@@ -152,11 +150,11 @@ class AliasManager constructor(
}
while
(!
expandedCommands
.
isEmpty
())
{
val
command
:
String
if
(
expandedCommands
[
0
].
trim
{
it
<=
' '
}
.
toLowerCase
(
Locale
.
US
).
startsWith
(
"/wait "
))
{
if
(
expandedCommands
[
0
].
trim
()
.
toLowerCase
(
Locale
.
US
).
startsWith
(
"/wait "
))
{
command
=
expandedCommands
.
joinToString
(
"; "
)
expandedCommands
.
clear
()
}
else
{
command
=
expandedCommands
[
0
]
command
=
expandedCommands
.
removeAt
(
0
)
}
previousCommands
.
add
(
IAliasManager
.
Command
(
bufferInfo
,
command
))
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment