Skip to content

Commit

Permalink
Merge pull request #7 from CriticalFlaw/2.2
Browse files Browse the repository at this point in the history
Version 2.2
  • Loading branch information
CriticalFlaw authored Aug 9, 2019
2 parents 8e12d71 + d686699 commit b63b989
Show file tree
Hide file tree
Showing 103 changed files with 2,018 additions and 1,263 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,5 @@ healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/

# End of https://www.gitignore.io/api/visualstudio
# End of https://www.gitignore.io/api/visualstudio
src/FlawBOT.Core/config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using DSharpPlus;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Converters;
using DSharpPlus.CommandsNext.Entities;
using DSharpPlus.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FlawBOT.Common
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
using DSharpPlus.Entities;
using FlawBOT.Models;
using Steam.Models.TF2;
using System;
using System.Collections.Generic;
using System;
using System.Reflection;
using DSharpPlus.Entities;

namespace FlawBOT.Common
{
public class SharedData
{
public static string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
public static string Name { get; } = "FlawBOT";
public static string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
public static string GitHubLink { get; set; } = "https://github.com/CriticalFlaw/FlawBOT/";
public static string InviteLink { get; } = "https://discordapp.com/oauth2/authorize?client_id=339833029013012483&scope=bot&permissions=66186303";
public static DiscordColor DefaultColor { get; set; } = new DiscordColor("#00FF7F");
public static DateTime ProcessStarted { get; set; }
public static Dictionary<uint, string> SteamAppList { get; set; } = new Dictionary<uint, string>();
public static Dictionary<uint, SchemaItem> TF2ItemSchema { get; set; } = new Dictionary<uint, SchemaItem>();
public static List<string> PokemonList { get; set; } = new List<string>();
public static TokenData Tokens { get; set; } = new TokenData();
}
}
20 changes: 20 additions & 0 deletions src/FlawBOT.Core/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-stretch-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["FlawBOT.Core/FlawBOT.Core.csproj", "FlawBOT.Core/"]
COPY ["FlawBOT.Core/NuGet.Config", "FlawBOT.Core/"]
COPY ["FlawBOT.Framework/FlawBOT.Framework.csproj", "FlawBOT.Framework/"]
RUN dotnet restore "FlawBOT.Core/FlawBOT.Core.csproj"
COPY . .
WORKDIR "/src/FlawBOT.Core"
RUN dotnet build "FlawBOT.Core.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "FlawBOT.Core.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "FlawBOT.Core.dll"]
50 changes: 50 additions & 0 deletions src/FlawBOT.Core/FlawBOT.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<ApplicationIcon>icon.ico</ApplicationIcon>
<StartupObject>FlawBOT.Program</StartupObject>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.2.0</Version>
<Win32Resource />
<LangVersion>7.2</LangVersion>
<AssemblyVersion>2.2.0</AssemblyVersion>
<FileVersion>2.2.0</FileVersion>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<AssemblyName>FlawBOT.Core</AssemblyName>
<RootNamespace>FlawBOT.Core</RootNamespace>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Prefer32Bit>false</Prefer32Bit>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<None Remove="config.json" />
</ItemGroup>

<ItemGroup>
<Content Include="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.0.0-nightly-00623" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.0.0-nightly-00623" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.0.0-nightly-00623" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FlawBOT.Framework\FlawBOT.Framework.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="PokemonTcgSdk">
<HintPath>..\FlawBOT.Framework\Resources\PokemonTcgSdk.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using DSharpPlus;
using System;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity;
using FlawBOT.Common;
using FlawBOT.Models;
using FlawBOT.Services;
using System;
using System.Threading.Tasks;
using FlawBOT.Framework.Models;
using FlawBOT.Framework.Services;

namespace FlawBOT.Modules.Bot
namespace FlawBOT.Modules
{
[Group("bot")]
[Description("Basic commands for interacting with FlawBOT")]
Expand All @@ -29,9 +29,9 @@ public async Task BotInfo(CommandContext ctx)
.WithDescription("A multipurpose Discord bot written in C# with [DSharpPlus](https://github.com/DSharpPlus/DSharpPlus/).")
.AddField(":clock1: Uptime", $"{(int)uptime.TotalDays:00} days {uptime.Hours:00}:{uptime.Minutes:00}:{uptime.Seconds:00}", true)
.AddField(":link: Links", $"[Commands]({SharedData.GitHubLink}wiki) **|** [Invite]({SharedData.InviteLink}) **|** [GitHub]({SharedData.GitHubLink})", true)
.WithFooter($"Thank you for using {SharedData.Name} (v{SharedData.Version})")
.WithFooter("Thank you for using " + SharedData.Name + $" (v{SharedData.Version})")
.WithUrl(SharedData.GitHubLink)
.WithColor(DiscordColor.Aquamarine);
.WithColor(SharedData.DefaultColor);
await ctx.RespondAsync(embed: output.Build());
}

Expand All @@ -45,7 +45,7 @@ public async Task BotInfo(CommandContext ctx)
public async Task LeaveAsync(CommandContext ctx)
{
await BotServices.SendEmbedAsync(ctx, $"Are you sure you want {SharedData.Name} to leave this server?\nRespond with **yes** to proceed or wait 10 seconds to cancel this operation.");
var interactivity = await ctx.Client.GetInteractivity().WaitForMessageAsync(m => m.Channel.Id == ctx.Channel.Id && m.Content.ToLowerInvariant() == "yes", TimeSpan.FromSeconds(10));
var interactivity = await ctx.Client.GetInteractivity().WaitForMessageAsync(m => m.Channel.Id == ctx.Channel.Id && m.Author.Id == ctx.User.Id && m.Content.ToLowerInvariant() == "yes", TimeSpan.FromSeconds(10));
if (interactivity.Result == null)
await BotServices.SendEmbedAsync(ctx, "Request timed out...");
else
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task ReportIssue(CommandContext ctx,
await ctx.RespondAsync("Please provide more information on the issue (50 characters minimum).");
else
{
await ctx.RespondAsync("The following information will be sent to the developer for investigation: User ID, Server ID, Server Name and Server Owner Name.\nRespond with **yes** in the next 10 seconds to proceed, otherwise the operation will be cancelled.");
await BotServices.SendEmbedAsync(ctx, "The following information will be sent to the developer for investigation: User ID, Server ID, Server Name and Server Owner Name.\nRespond with **yes** in the next 10 seconds to proceed, otherwise the operation will be cancelled.");
var interactivity = await ctx.Client.GetInteractivity().WaitForMessageAsync(m => m.Channel.Id == ctx.Channel.Id && m.Author.Id == ctx.User.Id && m.Content.ToLowerInvariant() == "yes", TimeSpan.FromSeconds(10));
if (interactivity.Result == null)
await BotServices.SendEmbedAsync(ctx, "Request timed out...");
Expand All @@ -95,7 +95,7 @@ public async Task ReportIssue(CommandContext ctx,
.AddField("Server", ctx.Guild.Name + $" (ID: {ctx.Guild.Id})")
.AddField("Owner", ctx.Guild.Owner.Username + "#" + ctx.Guild.Owner.Discriminator)
.AddField("Confirm", $"[Click here to add this issue to GitHub]({SharedData.GitHubLink}/issues/new)")
.WithColor(DiscordColor.Turquoise);
.WithColor(SharedData.DefaultColor);
await dm.SendMessageAsync(embed: output.Build());
await BotServices.SendEmbedAsync(ctx, "Thank You! Your report has been submitted.", EmbedType.Good);
}
Expand All @@ -112,8 +112,7 @@ public async Task ReportIssue(CommandContext ctx,
public Task Say(CommandContext ctx,
[Description("Message for the bot to repeat")] [RemainingText] string message)
{
message = (string.IsNullOrWhiteSpace(message)) ? ":thinking:" : message;
return ctx.RespondAsync(message);
return ctx.RespondAsync((string.IsNullOrWhiteSpace(message)) ? ":thinking:" : message);
}

#endregion COMMAND_SAY
Expand All @@ -125,7 +124,8 @@ public Task Say(CommandContext ctx,
public async Task Uptime(CommandContext ctx)
{
var uptime = DateTime.Now - SharedData.ProcessStarted;
await BotServices.SendEmbedAsync(ctx, ":clock1: " + SharedData.Name + $" has been online for {(int)uptime.TotalDays:00} days ({uptime.Hours:00}:{uptime.Minutes:00}:{uptime.Seconds:00})");
var days = (uptime.Days > 0) ? $"({uptime.Days:00} days)" : null;
await BotServices.SendEmbedAsync(ctx, ":clock1: " + SharedData.Name + $" has been online for {uptime.Hours:00}:{uptime.Minutes:00} {days}");
}

#endregion COMMAND_UPTIME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using DSharpPlus;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using FlawBOT.Common;
using FlawBOT.Models;
using FlawBOT.Services;
using FlawBOT.Services.Games;
using FlawBOT.Services.Search;
using System.Threading.Tasks;
using FlawBOT.Framework.Models;
using FlawBOT.Framework.Services;

namespace FlawBOT.Modules.Bot
namespace FlawBOT.Modules
{
[Group("sudo"), Hidden]
[Description("Owner commands for controlling FlawBOT")]
Expand All @@ -32,6 +30,7 @@ public async Task SetBotActivity(CommandContext ctx,
}
else
{
// TODO: Set the activity type
var game = new DiscordActivity(activity);
await ctx.Client.UpdateStatusAsync(activity: game);
await BotServices.SendEmbedAsync(ctx, SharedData.Name + " activity has been changed to " + Formatter.Bold("Playing " + game.Name), EmbedType.Good);
Expand Down Expand Up @@ -110,11 +109,35 @@ public async Task Update(CommandContext ctx)
{
var message = await ctx.RespondAsync("Starting update...");
await SteamService.UpdateSteamListAsync().ConfigureAwait(false);
await TeamFortressService.UpdateTF2SchemaAsync().ConfigureAwait(false);
await TeamFortressService.LoadTF2SchemaAsync().ConfigureAwait(false);
await PokemonService.UpdatePokemonListAsync().ConfigureAwait(false);
await message.ModifyAsync("Starting update...done!");
}

#endregion COMMAND_UPDATE

#region COMMAND_USERNAME

[RequireOwner]
[Command("username"), Hidden]
[Aliases("setusername", "name", "setname", "nickname")]
[Description("Set FlawBOT's username")]
public async Task SetBotUsername(CommandContext ctx,
[Description("New bot username")] [RemainingText] string name)
{
var oldUsername = ctx.Client.CurrentUser.Username;
if (string.IsNullOrWhiteSpace(name))
{
await ctx.Client.UpdateCurrentUserAsync(username: SharedData.Name);
await BotServices.SendEmbedAsync(ctx, oldUsername + " username has been changed to " + SharedData.Name);
}
else
{
await ctx.Client.UpdateCurrentUserAsync(username: name);
await BotServices.SendEmbedAsync(ctx, oldUsername + " username has been changed to " + ctx.Client.CurrentUser.Username, EmbedType.Good);
}
}

#endregion COMMAND_USERNAME
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using DSharpPlus.CommandsNext;
using System;
using System.Text;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.Interactivity;
using FlawBOT.Models;
using FlawBOT.Services;
using FlawBOT.Services.Games;
using PokemonTcgSdk;
using System;
using System.Text;
using System.Threading.Tasks;
using FlawBOT.Framework.Models;
using FlawBOT.Framework.Services;

namespace FlawBOT.Modules.Games
namespace FlawBOT.Modules
{
[Cooldown(3, 5, CooldownBucketType.Channel)]
public class PokemonModule : BaseCommandModule
Expand All @@ -30,22 +28,22 @@ public async Task Pokemon(CommandContext ctx,
{
foreach (var value in results.Cards)
{
var card = PokemonTcgSdk.Card.Find<Pokemon>(value.ID).Card;
var card = PokemonService.GetExactPokemonAsync(value.ID);
var output = new DiscordEmbedBuilder()
.WithTitle(card.Name + $" (PokeDex ID: {card.NationalPokedexNumber})")
.AddField("Subtype", card.SubType ?? "Unknown", true)
.AddField("Health Points", card.Hp ?? "Unknown", true)
.AddField("Artist", card.Artist ?? "Unknown", true)
.AddField("Rarity", card.Rarity ?? "Unknown", true)
.AddField("Series", card.Series ?? "Unknown", true)
.WithImageUrl((!string.IsNullOrWhiteSpace(card.ImageUrlHiRes)) ? card.ImageUrlHiRes : card.ImageUrl)
.WithImageUrl(card.ImageUrlHiRes ?? card.ImageUrl)
.WithColor(DiscordColor.Gold)
.WithFooter("Type next in the next 10 seconds for the next card");

var types = new StringBuilder();
foreach (var type in card.Types)
types.Append(type);
if (types.Length != 0)
output.AddField("Type(s)", types.ToString(), true);
output.AddField("Type(s)", types.ToString() ?? "Unknown", true);
await ctx.RespondAsync(embed: output.Build());

var interactivity = await ctx.Client.GetInteractivity().WaitForMessageAsync(m => m.Channel.Id == ctx.Channel.Id && m.Content.ToLowerInvariant() == "next", TimeSpan.FromSeconds(10));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using DSharpPlus.CommandsNext;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using FlawBOT.Models;
using FlawBOT.Services;
using FlawBOT.Services.Games;
using System.Threading.Tasks;
using FlawBOT.Framework.Models;
using FlawBOT.Framework.Services;

namespace FlawBOT.Modules.Games
namespace FlawBOT.Modules
{
[Cooldown(3, 5, CooldownBucketType.Channel)]
public class SmashModule : BaseCommandModule
{
#region COMMAND_SMASH

[Command("smash")]
[Aliases("smashbros")]
[Description("Retrieve Smash Ultimate character information")]
[Aliases("smashbros", "sb", "sbu")]
[Description("Retrieve Smash Bros. Ultimate character information")]
public async Task GetCharacter(CommandContext ctx,
[Description("Name of the Smash character")] [RemainingText] string query)
{
Expand All @@ -27,10 +28,21 @@ public async Task GetCharacter(CommandContext ctx,
{
var output = new DiscordEmbedBuilder()
.WithTitle(results.DisplayName)
.WithDescription($"[Attributes]({results.Related.Ultimate.Attributes}) **|** [Movements]({results.Related.Ultimate.Movements}) **|** [Moves]({results.Related.Ultimate.Moves})")
.WithThumbnailUrl(results.ThumbnailUrl)
.WithColor(new DiscordColor(results.ColorTheme))
.WithUrl(results.FullUrl);

var attributes = await SmashService.GetCharacterAttributesAsync(results.OwnerId);
var attributesProcessed = new List<string>();
foreach (var attribute in attributes)
{
if (attributesProcessed.Contains(attribute.Name)) continue;
var values = new StringBuilder();
foreach (var value in attribute.Attributes)
values.Append(value.Name + ": " + value.Value + "\n");
output.AddField(attribute.Name, values.ToString() ?? "Unknown", true);
attributesProcessed.Add(attribute.Name);
}
await ctx.RespondAsync(embed: output.Build());
}
}
Expand Down
Loading

0 comments on commit b63b989

Please sign in to comment.