Merge pull request #186 from 13xforever/vnext

I swear this is the last one [for today]
This commit is contained in:
Ilya 2019-01-25 02:02:26 +05:00 committed by GitHub
commit f131c14ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 33 deletions

View File

@ -24,11 +24,12 @@ namespace CompatBot.Commands
[GroupCommand] [GroupCommand]
public async Task ShowExplanation(CommandContext ctx, [RemainingText, Description("Term to explain")] string term) public async Task ShowExplanation(CommandContext ctx, [RemainingText, Description("Term to explain")] string term)
{ {
string inSpecificLocation = null; if (string.IsNullOrEmpty(term))
if (!LimitedToSpamChannel.IsSpamChannel(ctx.Channel))
{ {
var spamChannel = await ctx.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false); var ch = LimitedToSpamChannel.IsSpamChannel(ctx.Channel) ? ctx.Channel : await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false);
inSpecificLocation = $" in {spamChannel.Mention} or bot DMs"; await ch.SendMessageAsync("Please specify term to explain").ConfigureAwait(false);
await List(ctx).ConfigureAwait(false);
return;
} }
if (!await DiscordInviteFilter.CheckMessageForInvitesAsync(ctx.Client, ctx.Message).ConfigureAwait(false)) if (!await DiscordInviteFilter.CheckMessageForInvitesAsync(ctx.Client, ctx.Message).ConfigureAwait(false))
@ -37,12 +38,6 @@ namespace CompatBot.Commands
if (!await AntipiracyMonitor.IsClean(ctx.Client, ctx.Message).ConfigureAwait(false)) if (!await AntipiracyMonitor.IsClean(ctx.Client, ctx.Message).ConfigureAwait(false))
return; return;
if (string.IsNullOrEmpty(term))
{
await ctx.RespondAsync($"You may want to look at available terms by using `{Config.CommandPrefix}explain list`{inSpecificLocation}").ConfigureAwait(false);
return;
}
term = term.ToLowerInvariant(); term = term.ToLowerInvariant();
using (var db = new BotDb()) using (var db = new BotDb())
{ {
@ -81,6 +76,12 @@ namespace CompatBot.Commands
} }
} }
string inSpecificLocation = null;
if (!LimitedToSpamChannel.IsSpamChannel(ctx.Channel))
{
var spamChannel = await ctx.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false);
inSpecificLocation = $" in {spamChannel.Mention} or bot DMs";
}
var msg = $"Unknown term `{term.Sanitize()}`. Use `{Config.CommandPrefix}explain list` to look at defined terms{inSpecificLocation}"; var msg = $"Unknown term `{term.Sanitize()}`. Use `{Config.CommandPrefix}explain list` to look at defined terms{inSpecificLocation}";
await ctx.RespondAsync(msg).ConfigureAwait(false); await ctx.RespondAsync(msg).ConfigureAwait(false);
} }

View File

@ -196,7 +196,7 @@ namespace CompatBot.Commands
[Command("rate"), Cooldown(20, 60, CooldownBucketType.Channel)] [Command("rate"), Cooldown(20, 60, CooldownBucketType.Channel)]
[Description("Gives a ~~random~~ expert judgment on the matter at hand")] [Description("Gives a ~~random~~ expert judgment on the matter at hand")]
public async Task Rate(CommandContext ctx, [RemainingText, Description("Something to rate")] string whatever) public async Task Rate(CommandContext ctx, [RemainingText, Description("Something to rate")] string whatever = "")
{ {
try try
{ {
@ -247,6 +247,28 @@ namespace CompatBot.Commands
suffix = "'s" + suffix; suffix = "'s" + suffix;
word = word.Substring(0, word.Length - 2); word = word.Substring(0, word.Length - 2);
} }
void MakeCustomRoleRating(DiscordMember m)
{
if (m != null && !choiceFlags.Contains('f'))
{
var roleList = m.Roles.ToList();
if (roleList.Any())
{
var role = roleList[new Random((prefix + m.Id).GetHashCode()).Next(roleList.Count)].Name?.ToLowerInvariant();
if (!string.IsNullOrEmpty(role))
{
if (role.EndsWith('s'))
role = role.Substring(0, role.Length - 1);
var article = Vowels.Contains(role[0]) ? "n" : "";
choices = RateAnswers.Concat(Enumerable.Repeat($"Pretty fly for a{article} {role} guy", RateAnswers.Count / 20)).ToList();
choiceFlags.Add('f');
}
}
}
}
if (Me.Contains(word)) if (Me.Contains(word))
result.Append(ctx.Message.Author.Mention); result.Append(ctx.Message.Author.Mention);
else if (word == "my") else if (word == "my")
@ -257,27 +279,12 @@ namespace CompatBot.Commands
result.Append(ctx.Client.CurrentUser.Mention).Append("'s"); result.Append(ctx.Client.CurrentUser.Mention).Append("'s");
else if (word.StartsWith("actually") || word.StartsWith("nevermind") || word.StartsWith("nvm")) else if (word.StartsWith("actually") || word.StartsWith("nevermind") || word.StartsWith("nvm"))
result.Clear(); result.Clear();
else if (i == 0 && await new DiscordUserConverter().ConvertAsync(word, ctx).ConfigureAwait(false) is Optional<DiscordUser> user && user.HasValue) else if (i == 0 && await new DiscordMemberConverter().ConvertAsync(word, ctx).ConfigureAwait(false) is Optional<DiscordMember> member && member.HasValue)
{ {
var u = user.Value; var m = member.Value;
result.Append(u.Mention); MakeCustomRoleRating(m);
var roles = ctx.Client.GetMember(u)?.Roles.ToList(); result.Append(m.Mention);
if (roles?.Count > 0)
{
var role = roles[new Random((prefix + u.Id).GetHashCode()).Next(roles.Count)].Name?.ToLowerInvariant();
if (!string.IsNullOrEmpty(role))
{
if (role.EndsWith('s'))
role = role.Substring(0, role.Length - 1);
var article = Vowels.Contains(role[0]) ? "n" : "";
if (!choiceFlags.Contains('f'))
{
choices = RateAnswers.Concat(Enumerable.Repeat($"Pretty fly for a{article} {role} guy", RateAnswers.Count / 20)).ToList();
choiceFlags.Add('f');
}
}
}
} }
else if (nekoMatch.Contains(word)) else if (nekoMatch.Contains(word))
{ {
@ -286,6 +293,7 @@ namespace CompatBot.Commands
choices = RateAnswers.Concat(Enumerable.Repeat("Ugh", RateAnswers.Count * 3)).ToList(); choices = RateAnswers.Concat(Enumerable.Repeat("Ugh", RateAnswers.Count * 3)).ToList();
choiceFlags.Add('n'); choiceFlags.Add('n');
} }
MakeCustomRoleRating(nekoMember);
result.Append(nekoUser.Mention); result.Append(nekoUser.Mention);
} }
else if (kdMatch.Contains(word)) else if (kdMatch.Contains(word))
@ -295,6 +303,7 @@ namespace CompatBot.Commands
choices = RateAnswers.Concat(Enumerable.Repeat("RSX genius", RateAnswers.Count * 3)).ToList(); choices = RateAnswers.Concat(Enumerable.Repeat("RSX genius", RateAnswers.Count * 3)).ToList();
choiceFlags.Add('k'); choiceFlags.Add('k');
} }
MakeCustomRoleRating(kdMember);
result.Append(kdUser.Mention); result.Append(kdUser.Mention);
} }
else else

View File

@ -1,6 +1,5 @@
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using CompatBot.Commands.Attributes;
using CompatBot.Database.Providers; using CompatBot.Database.Providers;
using CompatBot.Utils; using CompatBot.Utils;
using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext;
@ -23,7 +22,7 @@ namespace CompatBot.Commands
{ {
await ctx.ReactWithAsync(Config.Reactions.Success, await ctx.ReactWithAsync(Config.Reactions.Success,
$"{user.Mention} was successfully added as moderator!\n" + $"{user.Mention} was successfully added as moderator!\n" +
"Try using `!help` to see new commands available to you" $"Try using `{Config.CommandPrefix}help` to see new commands available to you"
).ConfigureAwait(false); ).ConfigureAwait(false);
} }
else else

View File

@ -69,7 +69,7 @@ namespace CompatBot.EventHandlers
var info = status.Results.First().Value; var info = status.Results.First().Value;
var botSpamChannel = await args.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false); var botSpamChannel = await args.Client.GetChannelAsync(Config.BotSpamId).ConfigureAwait(false);
var msg = $"{args.Author.Mention} {info.Title} is {info.Status.ToLowerInvariant()} since {info.ToUpdated()}\n" + var msg = $"{args.Author.Mention} {info.Title} is {info.Status.ToLowerInvariant()} since {info.ToUpdated()}\n" +
$"for more results please use compatibility list (<https://rpcs3.net/compatibility>) or `!c` command in {botSpamChannel.Mention} (`!c {gameTitle.Sanitize()}`)"; $"for more results please use compatibility list (<https://rpcs3.net/compatibility>) or `{Config.CommandPrefix}c` command in {botSpamChannel.Mention} (`!c {gameTitle.Sanitize()}`)";
await args.Channel.SendMessageAsync(msg).ConfigureAwait(false); await args.Channel.SendMessageAsync(msg).ConfigureAwait(false);
CooldownBuckets[args.Channel.Id] = DateTime.UtcNow; CooldownBuckets[args.Channel.Id] = DateTime.UtcNow;
} }