-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleHelpFormatter.cs
More file actions
122 lines (106 loc) · 4.17 KB
/
SimpleHelpFormatter.cs
File metadata and controls
122 lines (106 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// THIS FILE IS A PART OF EMZI0767'S BOT EXAMPLES
//
// --------
//
// Copyright 2017 Emzi0767
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// --------
//
// This is a commands example. It shows how to properly utilize
// CommandsNext, as well as use its advanced functionality.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Converters;
using DSharpPlus.CommandsNext.Entities;
namespace DSPlus.Examples
{
// help formatters can alter the look of default help command,
// this particular one replaces the embed with a simple text message.
public class SimpleHelpFormatter : IHelpFormatter
{
private StringBuilder MessageBuilder { get; }
public SimpleHelpFormatter()
{
this.MessageBuilder = new StringBuilder();
}
// this method is called first, it sets the current command's name
// if no command is currently being processed, it won't be called
public IHelpFormatter WithCommandName(string name)
{
this.MessageBuilder.Append("Command: ")
.AppendLine(Formatter.Bold(name))
.AppendLine();
return this;
}
// this method is called second, it sets the current command's
// description. if no command is currently being processed, it
// won't be called
public IHelpFormatter WithDescription(string description)
{
this.MessageBuilder.Append("Description: ")
.AppendLine(description)
.AppendLine();
return this;
}
// this method is called third, it is used when currently
// processed group can be executed as a standalone command,
// otherwise not called
public IHelpFormatter WithGroupExecutable()
{
this.MessageBuilder.AppendLine("This group is a standalone command.")
.AppendLine();
return this;
}
// this method is called fourth, it sets the current command's
// aliases. if no command is currently being processed, it won't
// be called
public IHelpFormatter WithAliases(IEnumerable<string> aliases)
{
this.MessageBuilder.Append("Aliases: ")
.AppendLine(string.Join(", ", aliases))
.AppendLine();
return this;
}
// this method is called fifth, it sets the current command's
// arguments. if no command is currently being processed, it won't
// be called
public IHelpFormatter WithArguments(IEnumerable<CommandArgument> arguments)
{
this.MessageBuilder.Append("Arguments: ")
.AppendLine(string.Join(", ", arguments.Select(xarg => $"{xarg.Name} ({xarg.Type.ToUserFriendlyName()})")))
.AppendLine();
return this;
}
// this method is called sixth, it sets the current group's subcommands
// if no group is being processed or current command is not a group, it
// won't be called
public IHelpFormatter WithSubcommands(IEnumerable<Command> subcommands)
{
this.MessageBuilder.Append("Subcommands: ")
.AppendLine(string.Join(", ", subcommands.Select(xc => xc.Name)))
.AppendLine();
return this;
}
// this is called as the last method, this should produce the final
// message, and return it
public CommandHelpMessage Build()
{
return new CommandHelpMessage(this.MessageBuilder.ToString().Replace("\r\n", "\n"));
}
}
}