Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 50 lines (44 sloc) 2.388 kB
3aaf5e5 @Strilanc [Bugs] Command System Rewrite
authored
1 Namespace Commands
2 ''' <summary>
3 ''' A command which processes arguments matching a template.
4 ''' </summary>
6c439ab @Strilanc Unit tests, DeadManSwitch rewrite, Command tweaks, etc
authored
5 <ContractClass(GetType(ContractClassTemplatedCommand(Of )))>
3aaf5e5 @Strilanc [Bugs] Command System Rewrite
authored
6 Public MustInherit Class TemplatedCommand(Of TTarget)
bedc2f6 @Strilanc Renamed Command<T> to BaseCommand<T>
authored
7 Inherits BaseCommand(Of TTarget)
3aaf5e5 @Strilanc [Bugs] Command System Rewrite
authored
8
9 Private ReadOnly _template As CommandTemplate
10
11 <ContractInvariantMethod()> Private Sub ObjectInvariant()
12 Contract.Invariant(_template IsNot Nothing)
13 End Sub
14
7e6fbc0 @Strilanc Removing redundant ByVals (Part 2)
authored
15 Protected Sub New(name As InvariantString,
16 template As InvariantString,
17 description As String,
18 Optional permissions As String = Nothing,
19 Optional extraHelp As String = Nothing,
20 Optional hasPrivateArguments As Boolean = False)
3aaf5e5 @Strilanc [Bugs] Command System Rewrite
authored
21 MyBase.New(name, template, description, permissions, extraHelp, hasPrivateArguments)
22 Contract.Requires(description IsNot Nothing)
23 Me._template = New CommandTemplate(template)
24 End Sub
25
7e6fbc0 @Strilanc Removing redundant ByVals (Part 2)
authored
26 Protected NotOverridable Overloads Overrides Function PerformInvoke(target As TTarget, user As BotUser, argument As String) As Task(Of String)
3aaf5e5 @Strilanc [Bugs] Command System Rewrite
authored
27 Dim arg = New CommandArgument(argument)
28 Dim argException = _template.TryFindMismatch(arg)
29 If argException IsNot Nothing Then Throw argException
30 Return PerformInvoke(target, user, arg)
31 End Function
32
33 '''<summary>Uses a parsed argument to processes the command.</summary>
7e6fbc0 @Strilanc Removing redundant ByVals (Part 2)
authored
34 Protected MustOverride Overloads Function PerformInvoke(target As TTarget, user As BotUser, argument As CommandArgument) As Task(Of String)
3aaf5e5 @Strilanc [Bugs] Command System Rewrite
authored
35 End Class
6c439ab @Strilanc Unit tests, DeadManSwitch rewrite, Command tweaks, etc
authored
36 <ContractClassFor(GetType(TemplatedCommand(Of )))>
37 Public MustInherit Class ContractClassTemplatedCommand(Of TTarget)
38 Inherits TemplatedCommand(Of TTarget)
39 Protected Sub New()
40 MyBase.New("", "", "")
41 End Sub
7e6fbc0 @Strilanc Removing redundant ByVals (Part 2)
authored
42 Protected Overrides Function PerformInvoke(target As TTarget, user As BotUser, argument As CommandArgument) As Task(Of String)
6c439ab @Strilanc Unit tests, DeadManSwitch rewrite, Command tweaks, etc
authored
43 Contract.Requires(target IsNot Nothing)
44 Contract.Requires(argument IsNot Nothing)
45 Contract.Ensures(Contract.Result(Of Task(Of String))() IsNot Nothing)
46 Throw New NotSupportedException
47 End Function
48 End Class
49 End Namespace
Something went wrong with that request. Please try again.