fix duplicate help entries and upsert for email addresses

This commit is contained in:
Ben Harris 2017-12-05 14:58:32 -05:00
parent f737922d3f
commit 77ea9dae53
5 changed files with 43 additions and 33 deletions

View File

@ -28,8 +28,8 @@ namespace dotbot.Commands
}
[Command("b")]
[Alias("cleverbot", "cl")]
[Command("cleverbot")]
[Alias("bb")]
[Summary("talk to benbot")]
public async Task ChatWithCleverBot([Remainder] [Summary("what you want to say to benbot")] string message)
{

View File

@ -15,7 +15,7 @@ namespace dotbot.Commands
{
using (var db = new DotbotDbContext())
{
if (db.Defs.Any(c => c.Id == Key))
if (db.Defs.Any(d => d.Id == Key))
db.Defs.Find(Key).Def = Value;
else
db.Defs.Add(new Definition { Id = Key, Def = Value });

View File

@ -21,7 +21,7 @@ namespace dotbot.Commands
[Command]
public async Task SendEmail(
[Summary("user to send to")] IUser recipient,
[Summary("user to send to")] IUser recipient,
[Summary("message to send")] [Remainder] string message
) {
using (var db = new DotbotDbContext())
@ -41,8 +41,8 @@ namespace dotbot.Commands
Credentials = new NetworkCredential(_config["gmail_login"], _config["tokens:gmail"])
};
smtp.Send(
$"{Context.User.Username}-{Context.Guild.Name}@benbot.tilde.team",
db.Emails.Find(recipient.Id).EmailAddress,
$"{Context.User.Username}-{Context.Guild.Name}@benbot.tilde.team",
db.Emails.Find(recipient.Id).EmailAddress,
$"benbot message from {Context.User.Username}",
message
);
@ -59,16 +59,32 @@ namespace dotbot.Commands
{
using (var db = new DotbotDbContext())
{
var id = Context.User.Id;
await Context.Message.DeleteAsync();
db.Emails.Add(new Email
{
Id = Context.User.Id,
EmailAddress = email
});
if (db.Emails.Any(e => e.Id == id))
db.Emails.Find(id).EmailAddress = email;
else
db.Emails.Add(new Email
{
Id = id,
EmailAddress = email
});
db.SaveChanges();
await ReplyAsync("your email has been saved");
}
}
[Command("show")]
[Summary("shows your saved email address")]
public async Task ShowEmail()
{
using (var db = new DotbotDbContext())
{
await Context.Message.DeleteAsync();
await ReplyAsync($"{Context.User.Mention}, your saved email is {db.Emails.Find(Context.User.Id)?.EmailAddress ?? "non existent"}");
}
}
}
}

View File

@ -3,6 +3,7 @@ using Discord.Commands;
using Microsoft.Extensions.Configuration;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace dotbot.Commands
{
@ -20,34 +21,30 @@ namespace dotbot.Commands
[Command("help")]
public async Task HelpAsync()
{
var builder = new EmbedBuilder()
var embed = new EmbedBuilder()
{
Color = new Color(114, 137, 218),
Description = "These are the commands you can use"
};
var cmds = new List<string>();
foreach (var module in _service.Modules)
{
string description = null;
string description = "";
foreach (var cmd in module.Commands)
{
if (cmds.Contains(cmd.Name)) continue;
cmds.Add(cmd.Name);
var result = await cmd.CheckPreconditionsAsync(Context);
if (result.IsSuccess)
description += $"{_config["prefix"]}{cmd.Aliases.First()}\n";
}
if (!string.IsNullOrWhiteSpace(description))
{
builder.AddField(x =>
{
x.Name = module.Name;
x.Value = description;
x.IsInline = false;
});
}
embed.AddField(module.Name, description);
}
await ReplyAsync("", false, builder.Build());
await ReplyAsync("", embed: embed);
}
[Command("help")]
@ -63,6 +60,7 @@ namespace dotbot.Commands
var builder = new EmbedBuilder()
{
Title = $"{Context.Client.CurrentUser.Username} Help",
Color = new Color(114, 137, 218),
Description = $"Here are some commands like **{command}**"
};
@ -70,14 +68,10 @@ namespace dotbot.Commands
foreach (var match in result.Commands)
{
var cmd = match.Command;
builder.AddField(x =>
{
x.Name = string.Join(", ", cmd.Aliases);
x.Value = $"Parameters: {string.Join(", ", cmd.Parameters.Select(p => p.Name))}\n" +
$"Summary: {cmd.Summary}";
x.IsInline = false;
});
builder.AddField(
string.Join(", ", cmd.Aliases),
$"Parameters: {string.Join(", ", cmd.Parameters.Select(p => p.Name))}\nSummary: {cmd.Summary}"
);
}
await ReplyAsync("", embed: builder.Build());

View File

@ -35,7 +35,7 @@ namespace dotbot.Commands
embed.AddField("Game", $"{user.Game?.ToString() ?? "not playing anything right now"}");
embed.AddField("Joined At", $"{user.JoinedAt:f}");
await ReplyAsync("", false, embed);
await ReplyAsync("", embed: embed);
}
@ -57,7 +57,7 @@ namespace dotbot.Commands
embed.AddField("Bot Uptime", $"{uptime:g}");
embed.AddField("Bot Memory Usage", $"{GC.GetTotalMemory(false) / 1000} mb");
await ReplyAsync("", false, embed);
await ReplyAsync("", embed: embed);
}
@ -92,7 +92,7 @@ namespace dotbot.Commands
);
embed.AddField("Server ID", $"{guild.Id}");
await ReplyAsync("", false, embed);
await ReplyAsync("", embed: embed);
}
}