Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more fixes #59

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.{cs,vb}]

# IDE0003: Remove qualification
dotnet_diagnostic.IDE0003.severity = silent
5 changes: 5 additions & 0 deletions MikuSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MikuSharp", "MikuSharp\Miku
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NicoNicoNii", "NicoNicoNii\NicoNicoNii\NicoNicoNii.csproj", "{38EC14AC-1188-412F-A0C2-FC0BDA2C6BDD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4CB3E9BD-AA4F-4000-9595-03AC74654E5A}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
50 changes: 21 additions & 29 deletions MikuSharp/Attributes/CustomMikuAttributes.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,41 @@
using DisCatSharp.ApplicationCommands.Attributes;
using System;
using System.Threading.Tasks;

using DisCatSharp.ApplicationCommands.Attributes;
using DisCatSharp.ApplicationCommands.Context;
using DisCatSharp.CommandsNext;
using DisCatSharp.CommandsNext.Attributes;

using System;
using System.Threading.Tasks;

namespace MikuSharp.Attributes;

/// <summary>
/// Defines that usage of this command is restricted to users in a vc.
/// Defines that usage of this command is restricted to users in a vc.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
public sealed class RequireUserVoicechatConnection : ApplicationCommandCheckBaseAttribute
{
public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
{
if (ctx.Member.VoiceState?.Channel != null)
return Task.FromResult(true);

return Task.FromResult(false);
}
public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
=> Task.FromResult(ctx.Member.VoiceState?.Channel != null);
}

/// <summary>
/// Defines that usage of this command is restricted to users & the bot in a vc.
/// Defines that usage of this command is restricted to users & the bot in a vc.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
public sealed class RequireUserAndBotVoicechatConnection : ApplicationCommandCheckBaseAttribute
{
public override async Task<bool> ExecuteChecksAsync(BaseContext ctx)
{
var bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id);
if (ctx.Member.VoiceState?.Channel != null && bot.VoiceState?.Channel != null)
return await Task.FromResult(true);

return await Task.FromResult(false);
}
public override async Task<bool> ExecuteChecksAsync(BaseContext ctx)
{
var bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id);
return ctx.Member.VoiceState?.Channel is not null && bot.VoiceState?.Channel is not null
? await Task.FromResult(true)
: await Task.FromResult(false);
}
}

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Class, AllowMultiple = false)]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Class)]
public sealed class NotStaffAttribute : CheckBaseAttribute
{
public override Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
{
return Task.FromResult(!ctx.User.IsStaff);
}
}
public override Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
=> Task.FromResult(!ctx.User.IsStaff);
}
297 changes: 143 additions & 154 deletions MikuSharp/Commands/About.cs

Large diffs are not rendered by default.

257 changes: 163 additions & 94 deletions MikuSharp/Commands/Action.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using DisCatSharp.ApplicationCommands;
using System.IO;
using System.Threading.Tasks;

using DisCatSharp.ApplicationCommands;
using DisCatSharp.ApplicationCommands.Attributes;
using DisCatSharp.ApplicationCommands.Context;
using DisCatSharp.Entities;
Expand All @@ -8,101 +11,167 @@

using MikuSharp.Utilities;

using System.IO;
using System.Threading.Tasks;

namespace MikuSharp.Commands;

[SlashCommandGroup("action", "Actions", dmPermission: false)]
[SlashCommandGroup("action", "Actions", false, [InteractionContextType.Guild, InteractionContextType.PrivateChannel], [ApplicationCommandIntegrationTypes.GuildInstall, ApplicationCommandIntegrationTypes.UserInstall])]
internal class Action : ApplicationCommandsModule
{
[SlashCommand("hug", "Hug someone!")]
public static async Task HugAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder());
var WSH = await ctx.Client.RestClient.GetWeebShAsync("hug", new[] { "" });
WSH.Embed.WithDescription($"{ctx.User.Mention} hugs {user.Mention} uwu");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{WSH.Extension}", WSH.ImgData);
builder.AddEmbed(WSH.Embed.Build());
await ctx.EditResponseAsync(builder);
}

[SlashCommand("kiss", "Kiss someone!")]
public static async Task KissAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder());
var WSH = await ctx.Client.RestClient.GetWeebShAsync("kiss", new[] { "" });
WSH.Embed.WithDescription($"{ctx.User.Mention} kisses {user.Mention} >~<");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{WSH.Extension}", WSH.ImgData);
builder.AddEmbed(WSH.Embed.Build());
await ctx.EditResponseAsync(builder);
}

[SlashCommand("lick", "Lick someone!")]
public static async Task LickAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder());
var WSH = await ctx.Client.RestClient.GetWeebShAsync("lick", new[] { "" });
WSH.Embed.WithDescription($"{ctx.User.Mention} licks {user.Mention} owo");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{WSH.Extension}", WSH.ImgData);
builder.AddEmbed(WSH.Embed.Build());
await ctx.EditResponseAsync(builder);
}

[SlashCommand("pat", "Pat someone!")]
public static async Task PatAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder());
var weeurl = await MikuBot._weebClient.GetRandomAsync("pat", new[] { "" });
Stream img = new MemoryStream(await ctx.Client.RestClient.GetByteArrayAsync(Other.resizeLink(weeurl.Url)));
var em = new DiscordEmbedBuilder();
em.WithDescription($"{ctx.User.Mention} pats {user.Mention} #w#");
em.WithImageUrl($"attachment://image.{MimeGuesser.GuessExtension(img)}");
em.WithFooter("by nekos.life");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{MimeGuesser.GuessExtension(img)}", img);
builder.AddEmbed(em.Build());
await ctx.EditResponseAsync(builder);
}

[SlashCommand("poke", "Poke someone!")]
public static async Task PokeAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder());
var weeurl = await MikuBot._weebClient.GetRandomAsync("poke", new[] { "" });
Stream img = new MemoryStream(await ctx.Client.RestClient.GetByteArrayAsync(Other.resizeLink(weeurl.Url)));
var em = new DiscordEmbedBuilder();
em.WithDescription($"{ctx.User.Mention} pokes {user.Mention} ÓwÒ");
em.WithImageUrl($"attachment://image.{MimeGuesser.GuessExtension(img)}");
em.WithFooter("by nekos.life");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{MimeGuesser.GuessExtension(img)}", img);
builder.AddEmbed(em.Build());
await ctx.EditResponseAsync(builder);
}

[SlashCommand("slap", "Slap someone!")]
public static async Task SlapAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder());
var weeurl = await MikuBot._weebClient.GetRandomAsync("slap", new[] { "" });
Stream img = new MemoryStream(await ctx.Client.RestClient.GetByteArrayAsync(Other.resizeLink(weeurl.Url)));
var em = new DiscordEmbedBuilder();
em.WithDescription($"{ctx.User.Mention} slaps {user.Mention} ÒwÓ");
em.WithImageUrl($"attachment://image.{MimeGuesser.GuessExtension(img)}");
em.WithFooter("by nekos.life");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{MimeGuesser.GuessExtension(img)}", img);
builder.AddEmbed(em.Build());
await ctx.EditResponseAsync(builder);
}
[SlashCommand("hug", "Hug someone!")]
public static async Task HugAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"{ctx.User.Mention} hugs {user.Mention} uwu"));
var wsh = await ctx.Client.RestClient.GetWeebShAsync("hug", [""]);
wsh.Embed.WithDescription($"{ctx.User.Mention} hugs {user.Mention} uwu");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{wsh.Extension}", wsh.ImgData);
builder.AddEmbed(wsh.Embed.Build());
await ctx.EditResponseAsync(builder);
if (ctx.Interaction.Context is InteractionContextType.Guild)
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(user.Mention).AddMention(new UserMention(user)));
}

[SlashCommand("kiss", "Kiss someone!")]
public static async Task KissAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"{ctx.User.Mention} kisses {user.Mention} >~<"));
var wsh = await ctx.Client.RestClient.GetWeebShAsync("kiss", [""]);
wsh.Embed.WithDescription($"{ctx.User.Mention} kisses {user.Mention} >~<");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{wsh.Extension}", wsh.ImgData);
builder.AddEmbed(wsh.Embed.Build());
await ctx.EditResponseAsync(builder);
if (ctx.Interaction.Context is InteractionContextType.Guild)
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(user.Mention).AddMention(new UserMention(user)));
}

[SlashCommand("lick", "Lick someone!")]
public static async Task LickAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"{ctx.User.Mention} licks {user.Mention} owo"));
var wsh = await ctx.Client.RestClient.GetWeebShAsync("lick", [""]);
wsh.Embed.WithDescription($"{ctx.User.Mention} licks {user.Mention} owo");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{wsh.Extension}", wsh.ImgData);
builder.AddEmbed(wsh.Embed.Build());
await ctx.EditResponseAsync(builder);
if (ctx.Interaction.Context is InteractionContextType.Guild)
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(user.Mention).AddMention(new UserMention(user)));
}

[SlashCommand("pat", "Pat someone!")]
public static async Task PatAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"{ctx.User.Mention} pats {user.Mention} #w#"));
var weeurl = await MikuBot.WeebClient.GetRandomAsync("pat", [""]);
Stream img = new MemoryStream(await ctx.Client.RestClient.GetByteArrayAsync(Other.ResizeLink(weeurl.Url)));
var em = new DiscordEmbedBuilder();
em.WithDescription($"{ctx.User.Mention} pats {user.Mention} #w#");
em.WithImageUrl($"attachment://image.{MimeGuesser.GuessExtension(img)}");
em.WithFooter("by nekos.life");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{MimeGuesser.GuessExtension(img)}", img);
builder.AddEmbed(em.Build());
await ctx.EditResponseAsync(builder);
if (ctx.Interaction.Context is InteractionContextType.Guild)
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(user.Mention).AddMention(new UserMention(user)));
}

[SlashCommand("poke", "Poke someone!")]
public static async Task PokeAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"{ctx.User.Mention} pokes {user.Mention} ÓwÒ"));
var weeurl = await MikuBot.WeebClient.GetRandomAsync("poke", [""]);
Stream img = new MemoryStream(await ctx.Client.RestClient.GetByteArrayAsync(Other.ResizeLink(weeurl.Url)));
var em = new DiscordEmbedBuilder();
em.WithDescription($"{ctx.User.Mention} pokes {user.Mention} ÓwÒ");
em.WithImageUrl($"attachment://image.{MimeGuesser.GuessExtension(img)}");
em.WithFooter("by nekos.life");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{MimeGuesser.GuessExtension(img)}", img);
builder.AddEmbed(em.Build());
await ctx.EditResponseAsync(builder);
if (ctx.Interaction.Context is InteractionContextType.Guild)
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(user.Mention).AddMention(new UserMention(user)));
}

[SlashCommand("slap", "Slap someone!")]
public static async Task SlapAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"{ctx.User.Mention} slaps {user.Mention} ÒwÓ"));
var weeurl = await MikuBot.WeebClient.GetRandomAsync("slap", [""]);
Stream img = new MemoryStream(await ctx.Client.RestClient.GetByteArrayAsync(Other.ResizeLink(weeurl.Url)));
var em = new DiscordEmbedBuilder();
em.WithDescription($"{ctx.User.Mention} slaps {user.Mention} ÒwÓ");
em.WithImageUrl($"attachment://image.{MimeGuesser.GuessExtension(img)}");
em.WithFooter("by nekos.life");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{MimeGuesser.GuessExtension(img)}", img);
builder.AddEmbed(em.Build());
await ctx.EditResponseAsync(builder);
if (ctx.Interaction.Context is InteractionContextType.Guild)
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(user.Mention).AddMention(new UserMention(user)));
}

[SlashCommand("bite", "Bite someone!")]
public static async Task BiteAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"{ctx.User.Mention} bites {user.Mention} x~x"));
var weeurl = await MikuBot.WeebClient.GetRandomAsync("bite", [""]);
Stream img = new MemoryStream(await ctx.Client.RestClient.GetByteArrayAsync(Other.ResizeLink(weeurl.Url)));
var em = new DiscordEmbedBuilder();
em.WithDescription($"{ctx.User.Mention} bites {user.Mention} x~x");
em.WithImageUrl($"attachment://image.{MimeGuesser.GuessExtension(img)}");
em.WithFooter("by nekos.life");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{MimeGuesser.GuessExtension(img)}", img);
builder.AddEmbed(em.Build());
await ctx.EditResponseAsync(builder);
if (ctx.Interaction.Context is InteractionContextType.Guild)
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(user.Mention).AddMention(new UserMention(user)));
}

[SlashCommand("nom", "Nom someone!")]
public static async Task NomAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"{ctx.User.Mention} noms {user.Mention} >:3c"));
var weeurl = await MikuBot.WeebClient.GetRandomAsync("nom", [""]);
Stream img = new MemoryStream(await ctx.Client.RestClient.GetByteArrayAsync(Other.ResizeLink(weeurl.Url)));
var em = new DiscordEmbedBuilder();
em.WithDescription($"{ctx.User.Mention} noms {user.Mention} >:3c");
em.WithImageUrl($"attachment://image.{MimeGuesser.GuessExtension(img)}");
em.WithFooter("by nekos.life");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{MimeGuesser.GuessExtension(img)}", img);
builder.AddEmbed(em.Build());
await ctx.EditResponseAsync(builder);
if (ctx.Interaction.Context is InteractionContextType.Guild)
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(user.Mention).AddMention(new UserMention(user)));
}

[SlashCommand("stare", "Stare at someone!")]
public static async Task StateAsync(InteractionContext ctx, [Option("user", "The user to execute the action with")] DiscordUser user)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent($"{ctx.User.Mention} stares {user.Mention} O.o"));
var weeurl = await MikuBot.WeebClient.GetRandomAsync("stare", [""]);
Stream img = new MemoryStream(await ctx.Client.RestClient.GetByteArrayAsync(Other.ResizeLink(weeurl.Url)));
var em = new DiscordEmbedBuilder();
em.WithDescription($"{ctx.User.Mention} stares at {user.Mention} O.o");
em.WithImageUrl($"attachment://image.{MimeGuesser.GuessExtension(img)}");
em.WithFooter("by nekos.life");

DiscordWebhookBuilder builder = new();
builder.AddFile($"image.{MimeGuesser.GuessExtension(img)}", img);
builder.AddEmbed(em.Build());
await ctx.EditResponseAsync(builder);
if (ctx.Interaction.Context is InteractionContextType.Guild)
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent(user.Mention).AddMention(new UserMention(user)));
}
}
Loading