fix duplicate help entries and upsert for email addresses
This commit is contained in:
parent
f737922d3f
commit
77ea9dae53
|
@ -28,8 +28,8 @@ namespace dotbot.Commands
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Command("b")]
|
[Command("cleverbot")]
|
||||||
[Alias("cleverbot", "cl")]
|
[Alias("bb")]
|
||||||
[Summary("talk to benbot")]
|
[Summary("talk to benbot")]
|
||||||
public async Task ChatWithCleverBot([Remainder] [Summary("what you want to say to benbot")] string message)
|
public async Task ChatWithCleverBot([Remainder] [Summary("what you want to say to benbot")] string message)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace dotbot.Commands
|
||||||
{
|
{
|
||||||
using (var db = new DotbotDbContext())
|
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;
|
db.Defs.Find(Key).Def = Value;
|
||||||
else
|
else
|
||||||
db.Defs.Add(new Definition { Id = Key, Def = Value });
|
db.Defs.Add(new Definition { Id = Key, Def = Value });
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace dotbot.Commands
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public async Task SendEmail(
|
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
|
[Summary("message to send")] [Remainder] string message
|
||||||
) {
|
) {
|
||||||
using (var db = new DotbotDbContext())
|
using (var db = new DotbotDbContext())
|
||||||
|
@ -41,8 +41,8 @@ namespace dotbot.Commands
|
||||||
Credentials = new NetworkCredential(_config["gmail_login"], _config["tokens:gmail"])
|
Credentials = new NetworkCredential(_config["gmail_login"], _config["tokens:gmail"])
|
||||||
};
|
};
|
||||||
smtp.Send(
|
smtp.Send(
|
||||||
$"{Context.User.Username}-{Context.Guild.Name}@benbot.tilde.team",
|
$"{Context.User.Username}-{Context.Guild.Name}@benbot.tilde.team",
|
||||||
db.Emails.Find(recipient.Id).EmailAddress,
|
db.Emails.Find(recipient.Id).EmailAddress,
|
||||||
$"benbot message from {Context.User.Username}",
|
$"benbot message from {Context.User.Username}",
|
||||||
message
|
message
|
||||||
);
|
);
|
||||||
|
@ -59,16 +59,32 @@ namespace dotbot.Commands
|
||||||
{
|
{
|
||||||
using (var db = new DotbotDbContext())
|
using (var db = new DotbotDbContext())
|
||||||
{
|
{
|
||||||
|
var id = Context.User.Id;
|
||||||
await Context.Message.DeleteAsync();
|
await Context.Message.DeleteAsync();
|
||||||
db.Emails.Add(new Email
|
if (db.Emails.Any(e => e.Id == id))
|
||||||
{
|
db.Emails.Find(id).EmailAddress = email;
|
||||||
Id = Context.User.Id,
|
else
|
||||||
EmailAddress = email
|
db.Emails.Add(new Email
|
||||||
});
|
{
|
||||||
|
Id = id,
|
||||||
|
EmailAddress = email
|
||||||
|
});
|
||||||
db.SaveChanges();
|
db.SaveChanges();
|
||||||
await ReplyAsync("your email has been saved");
|
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"}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ using Discord.Commands;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace dotbot.Commands
|
namespace dotbot.Commands
|
||||||
{
|
{
|
||||||
|
@ -20,34 +21,30 @@ namespace dotbot.Commands
|
||||||
[Command("help")]
|
[Command("help")]
|
||||||
public async Task HelpAsync()
|
public async Task HelpAsync()
|
||||||
{
|
{
|
||||||
var builder = new EmbedBuilder()
|
var embed = new EmbedBuilder()
|
||||||
{
|
{
|
||||||
Color = new Color(114, 137, 218),
|
Color = new Color(114, 137, 218),
|
||||||
Description = "These are the commands you can use"
|
Description = "These are the commands you can use"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var cmds = new List<string>();
|
||||||
foreach (var module in _service.Modules)
|
foreach (var module in _service.Modules)
|
||||||
{
|
{
|
||||||
string description = null;
|
string description = "";
|
||||||
foreach (var cmd in module.Commands)
|
foreach (var cmd in module.Commands)
|
||||||
{
|
{
|
||||||
|
if (cmds.Contains(cmd.Name)) continue;
|
||||||
|
cmds.Add(cmd.Name);
|
||||||
var result = await cmd.CheckPreconditionsAsync(Context);
|
var result = await cmd.CheckPreconditionsAsync(Context);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
description += $"{_config["prefix"]}{cmd.Aliases.First()}\n";
|
description += $"{_config["prefix"]}{cmd.Aliases.First()}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(description))
|
if (!string.IsNullOrWhiteSpace(description))
|
||||||
{
|
embed.AddField(module.Name, description);
|
||||||
builder.AddField(x =>
|
|
||||||
{
|
|
||||||
x.Name = module.Name;
|
|
||||||
x.Value = description;
|
|
||||||
x.IsInline = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await ReplyAsync("", false, builder.Build());
|
await ReplyAsync("", embed: embed);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("help")]
|
[Command("help")]
|
||||||
|
@ -63,6 +60,7 @@ namespace dotbot.Commands
|
||||||
|
|
||||||
var builder = new EmbedBuilder()
|
var builder = new EmbedBuilder()
|
||||||
{
|
{
|
||||||
|
Title = $"{Context.Client.CurrentUser.Username} Help",
|
||||||
Color = new Color(114, 137, 218),
|
Color = new Color(114, 137, 218),
|
||||||
Description = $"Here are some commands like **{command}**"
|
Description = $"Here are some commands like **{command}**"
|
||||||
};
|
};
|
||||||
|
@ -70,14 +68,10 @@ namespace dotbot.Commands
|
||||||
foreach (var match in result.Commands)
|
foreach (var match in result.Commands)
|
||||||
{
|
{
|
||||||
var cmd = match.Command;
|
var cmd = match.Command;
|
||||||
|
builder.AddField(
|
||||||
builder.AddField(x =>
|
string.Join(", ", cmd.Aliases),
|
||||||
{
|
$"Parameters: {string.Join(", ", cmd.Parameters.Select(p => p.Name))}\nSummary: {cmd.Summary}"
|
||||||
x.Name = string.Join(", ", cmd.Aliases);
|
);
|
||||||
x.Value = $"Parameters: {string.Join(", ", cmd.Parameters.Select(p => p.Name))}\n" +
|
|
||||||
$"Summary: {cmd.Summary}";
|
|
||||||
x.IsInline = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await ReplyAsync("", embed: builder.Build());
|
await ReplyAsync("", embed: builder.Build());
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace dotbot.Commands
|
||||||
embed.AddField("Game", $"{user.Game?.ToString() ?? "not playing anything right now"}");
|
embed.AddField("Game", $"{user.Game?.ToString() ?? "not playing anything right now"}");
|
||||||
embed.AddField("Joined At", $"{user.JoinedAt:f}");
|
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 Uptime", $"{uptime:g}");
|
||||||
embed.AddField("Bot Memory Usage", $"{GC.GetTotalMemory(false) / 1000} mb");
|
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}");
|
embed.AddField("Server ID", $"{guild.Id}");
|
||||||
|
|
||||||
await ReplyAsync("", false, embed);
|
await ReplyAsync("", embed: embed);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue