Skip to content

Commit

Permalink
Move all Structs to the Structs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Voltstro committed Jul 29, 2019
1 parent a128e1f commit 87113f0
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 40 deletions.
9 changes: 5 additions & 4 deletions Pootis-Bot/Core/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Diagnostics;
using Discord;
using Discord.WebSocket;
using Discord.Rest;
using Pootis_Bot.Entities;
using Pootis_Bot.Services;
using System.Diagnostics;
using Pootis_Bot.Structs;

namespace Pootis_Bot.Core
{
Expand Down Expand Up @@ -60,7 +61,7 @@ public async Task StartBot()
private Task ChannelDestroyed(SocketChannel channel)
{
GlobalServerList serverList = ServerLists.GetServer((channel as SocketGuildChannel).Guild);
GlobalServerList.VoiceChannel voiceChannel = serverList.GetVoiceChannel(channel.Id);
var voiceChannel = serverList.GetVoiceChannel(channel.Id);

//If the channel deleted was an auto voice channel, remove it from the list.
if(voiceChannel.Name != null)
Expand All @@ -79,7 +80,7 @@ private async Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState befor
//If we are adding an auto voice channel
if (after.VoiceChannel != null)
{
GlobalServerList.VoiceChannel voiceChannel = server.GetVoiceChannel(after.VoiceChannel.Id);
var voiceChannel = server.GetVoiceChannel(after.VoiceChannel.Id);
if (voiceChannel.Name != null)
{
RestVoiceChannel createdChannel = await after.VoiceChannel.Guild.CreateVoiceChannelAsync($"New {voiceChannel.Name} chat");
Expand Down Expand Up @@ -232,7 +233,7 @@ await ownerDM.SendMessageAsync($"{guild.Owner.Mention}, your server **{guild.Nam
}

//Check to see if all the auto voice channels are there
List<GlobalServerList.VoiceChannel> deleteAutoChannels = new List<GlobalServerList.VoiceChannel>();
List<VoiceChannel> deleteAutoChannels = new List<VoiceChannel>();
foreach(var autoChannel in server.VoiceChannels)
{
if (_client.GetChannel(autoChannel.ID) == null)
Expand Down
2 changes: 1 addition & 1 deletion Pootis-Bot/Core/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static class Global
// Main Server - Development Server
internal static readonly string[] discordServers = { "https://discord.creepysin.com", "https://discord.gg/m4YcsUa" };

internal static readonly string version = "0.2.8";
internal static readonly string version = "0.2.9";
internal static readonly string aboutMessage = $"Pootis Bot --- | --- {version}\n" +
$"Created by Creepysin licensed under the MIT license. Vist {githubPage}/blob/master/LICENSE.md for more info.\n\n" +
$"Pootis Robot icon by Valve\n" +
Expand Down
9 changes: 1 addition & 8 deletions Pootis-Bot/Entities/GlobalConfigFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Pootis_Bot.Structs;

namespace Pootis_Bot.Entities
{
Expand All @@ -24,14 +25,6 @@ public class GlobalConfigFile
//Help modules
public List<HelpModules> helpModules = new List<HelpModules>();

public struct ConfigApis
{
public string apiGiphyKey;
public string apiYoutubeKey;
public string apiGoogleSearchKey;
public string googleSearchEngineID;
}

public class HelpModules
{
public string group;
Expand Down
13 changes: 1 addition & 12 deletions Pootis-Bot/Entities/GlobalServerList.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Pootis_Bot.Structs;

namespace Pootis_Bot.Entities
{
Expand All @@ -25,18 +26,6 @@ public class GlobalServerList

public List<ulong> ActiveAutoVoiceChannels = new List<ulong>();

public struct VoiceChannel
{
public ulong ID { get; set; }
public string Name { get; set;}

public VoiceChannel(ulong id, string name)
{
ID = id;
Name = name;
}
}

public class CommandInfo
{
public string Command { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion Pootis-Bot/Modules/Audio/VoiceChannels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Pootis_Bot.Core;
using Pootis_Bot.Entities;
using Pootis_Bot.Preconditions;
using Pootis_Bot.Structs;

namespace Pootis_Bot.Modules.Audio
{
Expand All @@ -22,7 +23,7 @@ public async Task AddVoiceChannel(string baseName)

await Context.Channel.SendMessageAsync($"Added {baseName} as an auto voice channel.");

GlobalServerList.VoiceChannel voiceChannel = new GlobalServerList.VoiceChannel(channel.Id, baseName);
VoiceChannel voiceChannel = new VoiceChannel(channel.Id, baseName);

ServerLists.GetServer((SocketGuild)Context.Guild).VoiceChannels.Add(voiceChannel);
ServerLists.SaveServerList();
Expand Down
20 changes: 16 additions & 4 deletions Pootis-Bot/Modules/Fun/GiphySearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Discord.Commands;
using Pootis_Bot.Core;
using Pootis_Bot.Entities;
using Pootis_Bot.Structs;
using Pootis_Bot.Services.Fun;

namespace Pootis_Bot.Modules.Fun
Expand All @@ -27,12 +28,23 @@ public async Task CmdGiphySearch([Remainder] string search = "")
return;
}

GiphyData results = GiphyService.Search(search);
var results = GiphyService.Search(search);
if (!results.IsSuccessfull)
{
//This should never happen, since we check it at the start!
if(results.ErrorReason == ErrorReason.NoAPIKey)
return;
if(results.ErrorReason == ErrorReason.Error)
{
await Context.Channel.SendMessageAsync("Sorry, but an error occured while searching Giphy, please try again in a moment!");
return;
}
}

EmbedBuilder embed = new EmbedBuilder();
embed.WithTitle("Giphy Search: " + Global.Title(results.gifTitle));
embed.WithDescription($"**By**: {results.gifAuthor}\n**URL**: {results.GifLink}");
embed.WithImageUrl(results.gifUrl);
embed.WithTitle("Giphy Search: " + Global.Title(results.Data.gifTitle));
embed.WithDescription($"**By**: {results.Data.gifAuthor}\n**URL**: {results.Data.GifLink}");
embed.WithImageUrl(results.Data.gifUrl);
embed.WithFooter($"Search by {Context.User} @ ", Context.User.GetAvatarUrl());
embed.WithCurrentTimestamp();
embed.WithColor(FunCmdsConfig.giphyColor);
Expand Down
25 changes: 17 additions & 8 deletions Pootis-Bot/Services/Fun/GiphyService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using System.Net;
using Newtonsoft.Json;
using Pootis_Bot.Core;
using Pootis_Bot.Entities;
using Pootis_Bot.Structs;

namespace Pootis_Bot.Services.Fun
{
public static class GiphyService
{
public static GiphyData Search(string search)
public static GiphySearchResult Search(string search)
{
GiphySearchResult searchResult = new GiphySearchResult();

try
{
//Check to see if the token is null or white space
Expand All @@ -34,16 +36,23 @@ public static GiphyData Search(string search)
GifLink = dataObject.data[choose].bitly_gif_url.ToString()
};

return item;
searchResult.IsSuccessfull = true;
searchResult.Data = item;
return searchResult;
}
else
return null;
else
{
searchResult.IsSuccessfull = false;
searchResult.ErrorReason = ErrorReason.NoAPIKey;
return searchResult;
}
}
catch
{
return null;
}

searchResult.IsSuccessfull = false;
searchResult.ErrorReason = ErrorReason.Error;
return searchResult;
}
}
}
}
10 changes: 10 additions & 0 deletions Pootis-Bot/Structs/ConfigApis.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Pootis_Bot.Structs
{
public struct ConfigApis
{
public string apiGiphyKey;
public string apiYoutubeKey;
public string apiGoogleSearchKey;
public string googleSearchEngineID;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Pootis_Bot.Entities
namespace Pootis_Bot.Structs
{
public class GiphyData
public struct GiphyData
{
public string gifUrl;
public string gifTitle;
Expand Down
11 changes: 11 additions & 0 deletions Pootis-Bot/Structs/GiphySearchResults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Pootis_Bot.Structs
{
public enum ErrorReason { NoAPIKey, HTTPError, Error }

public struct GiphySearchResult
{
public bool IsSuccessfull { get; set; }
public ErrorReason ErrorReason { get; set; }
public GiphyData Data { get; set; }
}
}
14 changes: 14 additions & 0 deletions Pootis-Bot/Structs/VoiceChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Pootis_Bot.Structs
{
public struct VoiceChannel
{
public ulong ID { get; set; }
public string Name { get; set; }

public VoiceChannel(ulong id, string name)
{
ID = id;
Name = name;
}
}
}

0 comments on commit 87113f0

Please sign in to comment.