Skip to content

Commit

Permalink
Changed the quote system to store quotes into the database
Browse files Browse the repository at this point in the history
  • Loading branch information
MythicalCuddles committed Oct 13, 2019
1 parent 266a938 commit 1c0e540
Show file tree
Hide file tree
Showing 11 changed files with 669 additions and 393 deletions.
22 changes: 21 additions & 1 deletion DiscordBot/Database/DatabaseActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,27 @@ private static void CreateTablesIfNotExists()
"`banDescription` text COLLATE utf8mb4_unicode_ci NOT NULL," +
"`dateIssued` datetime NOT NULL," +
"PRIMARY KEY (`banID`)" +
") ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");

ExecuteNonQueryCommand("CREATE TABLE IF NOT EXISTS `quotes` (" +
"`quoteId` INT NOT NULL AUTO_INCREMENT," +
"`createdBy` BIGINT NOT NULL," +
"`acceptedBy` BIGINT NOT NULL," +
"`quoteText` TEXT NOT NULL," +
"`dateCreated` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP," +
"`createdIn` BIGINT NOT NULL," +
"`acceptedIn` BIGINT NOT NULL," +
"PRIMARY KEY (`quoteId`)" +
") ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");

ExecuteNonQueryCommand("CREATE TABLE IF NOT EXISTS `requested_quotes` (" +
"`requestQuoteId` INT NOT NULL AUTO_INCREMENT," +
"`requestedBy` BIGINT NOT NULL," +
"`quoteText` TEXT NOT NULL," +
"`dateCreated` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP," +
"`requestedIn` BIGINT NOT NULL," +
"PRIMARY KEY (`requestQuoteId`)" +
") ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
}
}
}
37 changes: 16 additions & 21 deletions DiscordBot/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ await Bot.SetGameAsync(Configuration.Load().StatusText, Configuration.Load().Sta

ModeratorModule.ActiveForDateTime = DateTime.Now;


var dataReader = DatabaseActivity.ExecuteReader("SELECT * FROM guilds;").Item1;
while (dataReader.Read())
{
Expand Down Expand Up @@ -158,7 +157,7 @@ await Bot.SetGameAsync(Configuration.Load().StatusText, Configuration.Load().Sta
await new LogMessage(LogSeverity.Info, "Startup", "-----------------------------------------------------------------").PrintToConsole();

await ReadyAddBansToDatabase(g).ConfigureAwait(false);
await new LogMessage(LogSeverity.Info, "Startup", "-----------------------------------------------------------------").PrintToConsole();
Methods.PrintConsoleSplitLine();
}

foreach (ulong id in guildsInDatabase)
Expand All @@ -168,22 +167,14 @@ await Bot.SetGameAsync(Configuration.Load().StatusText, Configuration.Load().Sta
Console.WriteLine(id + @" has been removed from the database.");
}

if (OfflineList.Any())
{
await new LogMessage(LogSeverity.Info, "Startup", OfflineList.Count + " new users added.").PrintToConsole();
foreach (Tuple<SocketGuildUser, SocketGuild> tupleList in OfflineList)
{
await new LogMessage(LogSeverity.Warning, "Startup", tupleList.Item1.Mention + " (" + tupleList.Item1.Id + ") joined " + tupleList.Item2.Name + " while the Bot was offline.").PrintToConsole();
}
}
else
{
await new LogMessage(LogSeverity.Info, "Startup", "No new users added.").PrintToConsole();
}

Quote.Quotes = Quote.LoadAll();
await new LogMessage(LogSeverity.Info, "Startup", "Loaded " + Quote.Quotes.Count + " Quotes from Database.").PrintToConsole();
RequestQuote.RequestQuotes = RequestQuote.LoadAll();
await new LogMessage(LogSeverity.Info, "Startup", "Loaded " + RequestQuote.RequestQuotes.Count + " RequestQuotes from Database.").PrintToConsole();

await new LogMessage(LogSeverity.Info, "Startup", Bot.CurrentUser.Username + " loaded.").PrintToConsole();

// Send message to log channel to announce bot is up and running.
// Send message to log channel to announce bot is up and running.
Version v = Assembly.GetExecutingAssembly().GetName().Version;
EmbedBuilder eb = new EmbedBuilder()
.WithTitle("Startup Notification")
Expand All @@ -193,15 +184,19 @@ await Bot.SetGameAsync(Configuration.Load().StatusText, Configuration.Load().Sta
.AddField("Version", v.Major + "." + v.Minor + "." + v.Build + "." + v.Revision, true)
.AddField("MelissaNet", VersionInfo.Version, true)
.AddField("Latency", Bot.Latency + "ms", true)
.AddField("Quotes", Quote.Quotes.Count, true)
.AddField("Quote Requests", RequestQuote.RequestQuotes.Count, true)
.WithCurrentTimestamp();
await Configuration.Load().LogChannelId.GetTextChannel().SendMessageAsync("", false, eb.Build());

if (OfflineList.Any())
{
foreach (Tuple<SocketGuildUser, SocketGuild> tupleList in OfflineList)
{
await Configuration.Load().LogChannelId.GetTextChannel().SendMessageAsync("[ALERT] While " + Bot.CurrentUser.Username + " was offline, " + tupleList.Item1.Mention + " (" + tupleList.Item1.Id + ") joined " + tupleList.Item2.Name + ". They have been added to the database.");
}
await new LogMessage(LogSeverity.Info, "Startup", OfflineList.Count + " new users added.").PrintToConsole();
foreach (Tuple<SocketGuildUser, SocketGuild> tupleList in OfflineList)
{
await new LogMessage(LogSeverity.Warning, "Startup", tupleList.Item1.Username + " (" + tupleList.Item1.Id + ") joined " + tupleList.Item2.Name + " while the Bot was offline.").PrintToConsole();
await Configuration.Load().LogChannelId.GetTextChannel().SendMessageAsync("[ALERT] While " + Bot.CurrentUser.Username + " was offline, " + tupleList.Item1.Mention + " (" + tupleList.Item1.Id + ") joined " + tupleList.Item2.Name + ". They have been added to the database.");
}
}
}

Expand Down
28 changes: 15 additions & 13 deletions DiscordBot/DiscordBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
<Reference Include="Discord.Addons.Interactive, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Discord.Addons.Interactive.1.0.1\lib\netstandard1.1\Discord.Addons.Interactive.dll</HintPath>
</Reference>
<Reference Include="Discord.Net.Commands, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.Commands.2.0.1\lib\net46\Discord.Net.Commands.dll</HintPath>
<Reference Include="Discord.Net.Commands, Version=2.1.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.Commands.2.1.1\lib\net46\Discord.Net.Commands.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Discord.Net.Core, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.Core.2.0.1\lib\net46\Discord.Net.Core.dll</HintPath>
<Reference Include="Discord.Net.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.Core.2.1.1\lib\net46\Discord.Net.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Discord.Net.Providers.UDPClient, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand All @@ -77,19 +77,19 @@
<HintPath>..\packages\Discord.Net.Providers.WS4Net.2.0.0-beta2-01001\lib\netstandard1.3\Discord.Net.Providers.WS4Net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Discord.Net.Rest, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.Rest.2.0.1\lib\net46\Discord.Net.Rest.dll</HintPath>
<Reference Include="Discord.Net.Rest, Version=2.1.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.Rest.2.1.1\lib\net46\Discord.Net.Rest.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Discord.Net.Rpc, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Discord.Net.Rpc.2.0.0-beta-00860\lib\net45\Discord.Net.Rpc.dll</HintPath>
</Reference>
<Reference Include="Discord.Net.Webhook, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.Webhook.2.0.1\lib\netstandard1.3\Discord.Net.Webhook.dll</HintPath>
<Reference Include="Discord.Net.Webhook, Version=2.1.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.Webhook.2.1.1\lib\netstandard1.3\Discord.Net.Webhook.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Discord.Net.WebSocket, Version=2.0.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.WebSocket.2.0.1\lib\net46\Discord.Net.WebSocket.dll</HintPath>
<Reference Include="Discord.Net.WebSocket, Version=2.1.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Discord.Net.WebSocket.2.1.1\lib\net46\Discord.Net.WebSocket.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Google.Authenticator, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -152,8 +152,9 @@
<Reference Include="System.Globalization.Calendars, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll</HintPath>
</Reference>
<Reference Include="System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net46\System.Interactive.Async.dll</HintPath>
<Reference Include="System.Interactive.Async, Version=3.2.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263">
<HintPath>..\packages\System.Interactive.Async.3.2.0\lib\net46\System.Interactive.Async.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
Expand Down Expand Up @@ -266,8 +267,9 @@
<Compile Include="Objects\Award.cs" />
<Compile Include="Objects\Channel.cs" />
<Compile Include="Objects\Guild.cs" />
<Compile Include="Objects\Quote.cs" />
<Compile Include="Objects\RequestQuote.cs" />
<Compile Include="Objects\User.cs" />
<Compile Include="Other\QuoteHandler.cs" />
<Compile Include="Other\VoteLinkHandler.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Loading

0 comments on commit 1c0e540

Please sign in to comment.