Skip to content

Commit

Permalink
Templating basics
Browse files Browse the repository at this point in the history
  • Loading branch information
LaineZ committed Nov 28, 2023
1 parent b968a27 commit a5d5be9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
4 changes: 2 additions & 2 deletions fs24bot3/Backend/Basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public async void Process()
var msg = new MessageGeneric(value, "testchannel",
new User("test", BotContext.Connection));
BotContext.MessageTrigger(msg);
await BotContext.ExecuteCommand(msg, "");
await BotContext.ExecuteCommand(msg, ConfigurationProvider.Config.Prefix);
}
}
}

public Task<bool> EnsureAuthorization(User user)
{
throw new NotImplementedException();
return Task.FromResult(true);
}
}
29 changes: 20 additions & 9 deletions fs24bot3/Commands/GenericCommandsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Runtime.InteropServices;
using KeraLua;
using System.Threading;
using HandlebarsDotNet;

namespace fs24bot3.Commands;
public sealed class GenericCommandsModule : ModuleBase<CommandProcessor.CustomCommandContext>
Expand Down Expand Up @@ -55,18 +56,28 @@ public async Task Help()
{
var cmds = Service.GetAllCommands();
string commandsOutput = Resources.help;
var template = Handlebars.Compile(commandsOutput);

var customCommands = Context.BotCtx.Connection.Query<SQL.CustomUserCommands>("SELECT * FROM CustomUserCommands ORDER BY length(Output) DESC");
string commandList = string.Join('\n', cmds.Where(x => !x.Checks.Any(x => x is Checks.CheckAdmin)).
Select(x =>
$"<strong>{ConfigurationProvider.Config.Prefix}{x.Name}</strong> {string.Join(' ', x.Parameters)}</p><p class=\"desc\">{x.Description}</p><p>Требования: {string.Join(' ', x.Checks)}</p><hr>"));
string customList = string.Join('\n', string.Join("\n", customCommands.
Select(x =>
$"<p>{ConfigurationProvider.Config.Prefix}{x.Command} Создал: <strong>{x.Nick}</strong> Lua: {(x.IsLua == 1 ? "Да" : "Нет")} </p>")));
var commandList = cmds.Select(x =>
{
return new
{
prefix = ConfigurationProvider.Config.Prefix,
name = x.Name,
parameters = x.Parameters.Select(x => x.Name),
description = x.Description,
checks = x.Checks.Select(x => x.ToString())
};
});
var data = new
{
commands = commandList
};


commandsOutput = commandsOutput.Replace("[CMDS]", commandList);
commandsOutput = commandsOutput.Replace("[CUSTOMLIST]", customList);

string link = await InternetServicesHelper.UploadToTrashbin(commandsOutput);
string link = await InternetServicesHelper.UploadToTrashbin(template(data));
await Context.SendMessage(Context.Channel,
$"Выложены команды по этой ссылке: {link} также вы можете написать {ConfigurationProvider.Config.Prefix}helpcmd имякоманды для получения дополнительной помощи");
}
Expand Down
46 changes: 29 additions & 17 deletions fs24bot3/Resources/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,61 @@
body {
margin: 0px;
padding: 0px;
}

a {
text-decoration: none;
color: #86796b;
}

a:hover {
color: #3A405A;
font-family: sans-serif;
color: #eff9d6;
background-color: #1b0326;
}

.menu {
background-color: #fbf1c7;
background-color: rgb(37, 4, 53);
}

.menuItem {
padding-left: 1em;
padding-bottom: 0.5em;
display: inline-block;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}

.content {
margin: 0.5em;
padding: 5px;
padding-top: 10px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}

.command {
border-bottom: 1px solid rgb(37, 4, 53);
}

code {
background-color: #7a1c4b;
padding: 5px;
border-radius: 10px;
}
</style>
</head>

<body>
<div class="menu">
<div class="menuItem">
<h3>fs24bot help</h3>
<h3>fs24bot help - список команд</h3>
</div>
</div>

<div class="content">
<h3>Список команд:</h3>
[CMDS]
<h3>Кастом команды:</h3>
[CUSTOMLIST]
<div class="commands">
{{#each commands}}
<div class="command">
<p>
<strong>{{this.prefix}}{{this.name}}</strong>
{{#each this.parameters}}
<code>{{this}}</code>
{{/each}}
</p>
<p>{{this.description}}</p>
</div>
{{/each}}
</div>
</div>
</div>
</body>

Expand Down
1 change: 1 addition & 0 deletions fs24bot3/fs24bot3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.4.3" />
<PackageReference Include="Genbox.WolframAlpha" Version="3.0.0-alpha1" />
<PackageReference Include="Handlebars.Net" Version="2.1.4" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.54" />
<PackageReference Include="MCQuery" Version="2022.7.13.192844" />
<PackageReference Include="NetIRC" Version="1.1.2-preview.2" />
Expand Down

0 comments on commit a5d5be9

Please sign in to comment.