Skip to content

Commit

Permalink
Bumped Version Number (2.6)
Browse files Browse the repository at this point in the history
- Speedrun command now has links for each available run category.
- Changed the format of news listing commands to embed the links into the title.
- Fixed exception handling on commands within the Google module.
- Cleaned up the look of various commands.
- Bumped version numbers 2.5 -> 2.6
  • Loading branch information
CriticalFlaw committed May 15, 2020
1 parent d58ea89 commit c3b67cd
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 65 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ StyleCopReport.xml
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
Expand Down Expand Up @@ -353,5 +352,4 @@ healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/

# End of https://www.gitignore.io/api/visualstudio
src/FlawBOT.Core/config.json
# End of https://www.gitignore.io/api/visualstudio
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Igor Nikitin
Copyright (c) 2020 Igor Nikitin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions src/FlawBOT.Core/FlawBOT.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<ApplicationIcon>icon.ico</ApplicationIcon>
<StartupObject>FlawBOT.Program</StartupObject>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.5.0</Version>
<Version>2.6.0</Version>
<Win32Resource />
<LangVersion>7.2</LangVersion>
<AssemblyVersion>2.5.0.0</AssemblyVersion>
<FileVersion>2.5.0.0</FileVersion>
<AssemblyVersion>2.6.0.0</AssemblyVersion>
<FileVersion>2.6.0.0</FileVersion>
<AssemblyName>FlawBOT.Core</AssemblyName>
<RootNamespace>FlawBOT.Core</RootNamespace>
<PackageTags />
Expand All @@ -20,7 +20,7 @@
<RepositoryType />
<Company>CriticalFlaw</Company>
<Product>FlawBOT</Product>
<Authors>CriticalFlaw</Authors>
<Authors>Igor Nikitin</Authors>
<NeutralLanguage>en-CA</NeutralLanguage>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/FlawBOT.Core/Modules/Games/SpeedrunModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task Speedrun(CommandContext ctx,
if (categories != null || categories.Count > 0)
{
foreach (var x in categories)
category.Append(x.Name).Append(!query.Equals(categories.Last()) ? ", " : string.Empty);
category.Append($"[{x.Name}]({x.Weblink}) **|** ");
}
output.AddField("Categories", category.ToString() ?? "Unknown", true);
await ctx.RespondAsync(embed: output.Build()).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion src/FlawBOT.Core/Modules/Games/TeamFortressModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public async Task TF2News(CommandContext ctx,
{
var output = new DiscordEmbedBuilder().WithColor(new DiscordColor("#E7B53B"));
foreach (var result in results.Take(5))
output.AddField(result.Title, result.Link.AbsoluteUri);
output.AddField(result.CreatedAt.Date.ToString(), $"{result.Type}: [{result.Title}]({result.Link.AbsoluteUri})");
await ctx.RespondAsync("Latest news articles from teamwork.tf", embed: output.Build()).ConfigureAwait(false);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/FlawBOT.Core/Modules/Misc/MiscModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,9 @@ public async Task IPLocation(CommandContext ctx,
else
{
var output = new DiscordEmbedBuilder()
.WithDescription($"Location: { results.City}, { results.Region}, { results.Country}")
.AddField("Longitude", results.Longitude.ToString(), true)
.AddField("Latitude", results.Latitude.ToString(), true)
.AddField("Location", $"{results.City}, {results.Region}, {results.Country}")
.AddField("ISP", results.ISP)
.AddField("Coordinates", $"{results.Latitude}°N, {results.Longitude}°W")
.WithFooter($"IP: {results.Query}")
.WithColor(new DiscordColor("#4d2f63"));
await ctx.RespondAsync(embed: output.Build()).ConfigureAwait(false);
Expand Down
6 changes: 3 additions & 3 deletions src/FlawBOT.Core/Modules/Search/GoogleModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task GetTime(CommandContext ctx,
{
if (!BotServices.CheckUserInput(location)) return;
var results = GoogleService.GetTimeDataAsync(location).Result;
if (results.status != "OK")
if (results == null || results.status != "OK")
await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
else
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task News(CommandContext ctx,

foreach (var result in results.Articles.Take(5))
{
output.AddField(result.Title, result.Url);
output.AddField(result.PublishDate.ToString(), $"[{result.Title}]({result.Url})");
results.Articles.Remove(result);
}
var message = await ctx.RespondAsync("Latest Google News articles from News API", embed: output.Build()).ConfigureAwait(false);
Expand All @@ -84,7 +84,7 @@ public async Task Weather(CommandContext ctx,
{
if (!BotServices.CheckUserInput(query)) return;
var results = await GoogleService.GetWeatherDataAsync(query).ConfigureAwait(false);
if (results.COD == 404)
if (results == null || results.COD == 404)
await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_LOCATION, EmbedType.Missing).ConfigureAwait(false);
else
{
Expand Down
13 changes: 9 additions & 4 deletions src/FlawBOT.Core/Modules/Search/ImgurModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using FlawBOT.Core.Properties;
using FlawBOT.Framework.Models;
using FlawBOT.Framework.Services;
Expand All @@ -22,12 +23,16 @@ public async Task Imgur(CommandContext ctx,
var results = ImgurService.GetImgurGalleryAsync(query).Result;
switch (results)
{
case GalleryAlbum _:
await ctx.RespondAsync(((GalleryAlbum)results).Link).ConfigureAwait(false);
case GalleryImage _:
var output = new DiscordEmbedBuilder()
.WithImageUrl(((GalleryImage)results).Link)
.WithFooter(((GalleryImage)results).Title ?? string.Empty)
.WithColor(new DiscordColor("#85BF25"));
await ctx.RespondAsync(embed: output.Build()).ConfigureAwait(false);
break;

case GalleryImage _:
await ctx.RespondAsync(((GalleryImage)results).Link).ConfigureAwait(false);
case GalleryAlbum _:
await ctx.RespondAsync(((GalleryAlbum)results).Link).ConfigureAwait(false);
break;

default:
Expand Down
4 changes: 2 additions & 2 deletions src/FlawBOT.Core/Modules/Search/NASAModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class NASAModule : BaseCommandModule
#region COMMAND_NASA

[Command("nasa")]
[Aliases("apod")]
[Aliases("apod", "space")]
[Description("Retrieve NASA's Astronomy Picture of the Day")]
public async Task NASA(CommandContext ctx)
{
Expand All @@ -24,7 +24,7 @@ public async Task NASA(CommandContext ctx)
else
{
var output = new DiscordEmbedBuilder()
.WithTitle(results.Title)
.WithDescription(results.Title)
.WithImageUrl(results.ImageHD ?? results.ImageSD)
.WithFooter(results.Description)
.WithColor(new DiscordColor("#0B3D91"));
Expand Down
29 changes: 27 additions & 2 deletions src/FlawBOT.Core/Modules/Search/RedditModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using FlawBOT.Core.Properties;
using FlawBOT.Framework.Models;
using FlawBOT.Framework.Services;
using System.Linq;
using System.Threading.Tasks;

namespace FlawBOT.Modules
Expand Down Expand Up @@ -31,8 +35,29 @@ public Task TopPost(CommandContext ctx, [Description("Subreddit.")] string query
private async Task RedditPost(CommandContext ctx, string query, RedditCategory category)
{
if (!BotServices.CheckUserInput(query)) return;
var results = RedditService.GetEmbeddedResults(query, category);
await ctx.RespondAsync("Search results for r/" + query, embed: results).ConfigureAwait(false);
var results = RedditService.GetResults(query, category);
if (results is null || results.Count == 0)
await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);

while (results.Count > 0)
{
var output = new DiscordEmbedBuilder()
.WithFooter("Type 'next' within 10 seconds for the next five posts.")
.WithColor(new DiscordColor("#FF4500"));

foreach (var result in results.Take(5))
{
output.AddField(result.Authors[0].Name, $"[{(result.Title.Text.Length < 500 ? result.Title.Text : result.Title.Text.Take(500) + "...")}]({result.Links.First().Uri})");
results.Remove(result);
}
var message = await ctx.RespondAsync("Search results for r/" + query, embed: output).ConfigureAwait(false);

if (results.Count == 5) continue;
var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false);
if (interactivity.Result is null) break;
await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false);
await BotServices.RemoveMessage(message).ConfigureAwait(false);
}
}

#endregion COMMAND_POST
Expand Down
2 changes: 1 addition & 1 deletion src/FlawBOT.Core/Modules/Server/BotModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task LeaveAsync(CommandContext ctx)
[Description("Ping the FlawBOT client")]
public async Task Ping(CommandContext ctx)
{
await ctx.RespondAsync($":ping_pong: Pong! Ping: **{ctx.Client.Ping}**ms").ConfigureAwait(false);
await BotServices.SendEmbedAsync(ctx, $":ping_pong: Pong! Ping: **{ctx.Client.Ping}**ms", EmbedType.Default).ConfigureAwait(false);
}

#endregion COMMAND_PING
Expand Down
10 changes: 5 additions & 5 deletions src/FlawBOT.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public static async Task Main(string[] args)
app.RunBotAsync().GetAwaiter().GetResult();
await Task.Delay(Timeout.Infinite).ConfigureAwait(false);
}
catch (Exception e)
catch (Exception ex)
{
Console.WriteLine($"\nException occurred: {e.GetType()} :\n{e.Message}");
if (!(e.InnerException is null))
Console.WriteLine($"Inner exception: {e.InnerException.GetType()} :\n{e.InnerException.Message}");
Console.WriteLine($"\nException occurred: {ex.GetType()} :\n{ex.Message}");
if (!(ex.InnerException is null))
Console.WriteLine($"Inner exception: {ex.InnerException.GetType()} :\n{ex.InnerException.Message}");
Console.ReadKey();
}
Console.WriteLine("\nShutting down...");
Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task RunBotAsync()
Commands.SetHelpFormatter<HelpFormatter>();

// Start the uptime counter
Console.Title = SharedData.Name + " (" + SharedData.Version + ")";
Console.Title = SharedData.Name + $" ({SharedData.Version})";
SharedData.ProcessStarted = DateTime.Now;
await SteamService.UpdateSteamListAsync().ConfigureAwait(false);
await TeamFortressService.UpdateTF2SchemaAsync().ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion src/FlawBOT.Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/FlawBOT.Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<value>This user doesn't have any roles.</value>
</data>
<data name="ERR_ROLE_NOT_ALLOWED" xml:space="preserve">
<value>You are unauthorised to remove roles from this user.</value>
<value>You are unauthorized to remove roles from this user.</value>
</data>
<data name="ERR_STEAM_CONNECT_FORMAT" xml:space="preserve">
<value>Invalid connection info, follow the format: 123.345.56.789:000; password hello</value>
Expand Down
8 changes: 4 additions & 4 deletions src/FlawBOT.Framework/FlawBOT.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyVersion>2.5.0.0</AssemblyVersion>
<Version>2.5.0</Version>
<FileVersion>2.5.0.0</FileVersion>
<Authors>CriticalFlaw</Authors>
<AssemblyVersion>2.7.0.0</AssemblyVersion>
<Version>2.6.0</Version>
<FileVersion>2.6.0.0</FileVersion>
<Authors>Igor Nikitin</Authors>
<Company>CriticalFlaw</Company>
<Product>FlawBOT</Product>
<Description>Multipurpose Discord bot written in C# using DSharpPlus. Application Framework.</Description>
Expand Down
21 changes: 2 additions & 19 deletions src/FlawBOT.Framework/Services/Search/RedditService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DSharpPlus.Entities;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Syndication;
Expand All @@ -9,23 +8,7 @@ namespace FlawBOT.Framework.Services
{
public static class RedditService
{
public static DiscordEmbed GetEmbeddedResults(string query, RedditCategory category = RedditCategory.Hot)
{
var results = GetResults(query, category);
if (results is null || results.Count == 0)
return new DiscordEmbedBuilder
{
Description = ":warning: No results found!",
Color = new DiscordColor("#FF4500")
};
results = (results.Count > 5) ? results.Take(5).ToList() : results;
var output = new DiscordEmbedBuilder { Color = new DiscordColor("#FF4500") };
foreach (var result in results)
output.AddField(result.Title.Text.Length < 500 ? result.Title.Text : result.Title.Text.Take(500) + "...", result.Links.First().Uri.ToString());
return output.Build();
}

private static List<SyndicationItem> GetResults(string query, RedditCategory category)
public static List<SyndicationItem> GetResults(string query, RedditCategory category)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions src/FlawBOT.Test/FlawBOT.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<IsPackable>false</IsPackable>
<AssemblyVersion>2.5.0.0</AssemblyVersion>
<FileVersion>2.5.0.0</FileVersion>
<Version>2.5.0</Version>
<Authors>CriticalFlaw</Authors>
<Version>2.6.0</Version>
<Authors>Igor Nikitin</Authors>
<Company>CriticalFlaw</Company>
<Product>FlawBOT</Product>
<Description>Multipurpose Discord bot written in C# using DSharpPlus. Application Tests.</Description>
Expand Down
4 changes: 2 additions & 2 deletions src/FlawBOT.Test/Games/TeamFortressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public void GetSchemaItem()
[Test]
public void GetServers()
{
Assert.IsNotNull(TeamFortressService.GetServersAsync("payload").Result);
Assert.IsNull(TeamFortressService.GetServersAsync("payloader").Result);
Assert.IsNotNull(TeamFortressService.GetGameModeServerAsync("payload").Result);
Assert.IsNull(TeamFortressService.GetGameModeServerAsync("payloader").Result);
}

[Test, Order(1)]
Expand Down
9 changes: 3 additions & 6 deletions src/FlawBOT.Test/Search/RedditTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ internal class RedditTests
[Test]
public void GetEmbeddedResults()
{
Assert.IsNotNull(RedditService.GetEmbeddedResults("AskReddit", RedditCategory.Hot));
Assert.IsNotNull(RedditService.GetEmbeddedResults("AskReddit", RedditCategory.New));
Assert.IsNotNull(RedditService.GetEmbeddedResults("AskReddit", RedditCategory.Top));
Assert.IsTrue(RedditService.GetEmbeddedResults("AskDinosaurs", RedditCategory.Hot).Description.Contains(":warning:"));
Assert.IsTrue(RedditService.GetEmbeddedResults("AskDinosaurs", RedditCategory.New).Description.Contains(":warning:"));
Assert.IsTrue(RedditService.GetEmbeddedResults("AskDinosaurs", RedditCategory.Top).Description.Contains(":warning:"));
Assert.IsNotNull(RedditService.GetResults("AskReddit", RedditCategory.Hot));
Assert.IsNotNull(RedditService.GetResults("AskReddit", RedditCategory.New));
Assert.IsNotNull(RedditService.GetResults("AskReddit", RedditCategory.Top));
}
}
}

0 comments on commit c3b67cd

Please sign in to comment.