Skip to content

Commit 210748f

Browse files
committed
Remove iJSD-specific commands & Big refactor
1 parent 04a35be commit 210748f

14 files changed

+323
-522
lines changed

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ StyleCopReport.xml
9090
*.tmp_proj
9191
*_wpftmp.csproj
9292
*.log
93+
*.tlog
9394
*.vspscc
9495
*.vssscc
9596
.builds
@@ -205,6 +206,9 @@ PublishScripts/
205206
*.nuget.props
206207
*.nuget.targets
207208

209+
# Nuget personal access tokens and Credentials
210+
nuget.config
211+
208212
# Microsoft Azure Build Output
209213
csx/
210214
*.build.csdef
@@ -360,3 +364,25 @@ MigrationBackup/
360364

361365
# Fody - auto-generated XML schema
362366
FodyWeavers.xsd
367+
368+
# VS Code files for those working on multiple tools
369+
.vscode/*
370+
!.vscode/settings.json
371+
!.vscode/tasks.json
372+
!.vscode/launch.json
373+
!.vscode/extensions.json
374+
*.code-workspace
375+
376+
# Local History for Visual Studio Code
377+
.history/
378+
379+
# Windows Installer files from build outputs
380+
*.cab
381+
*.msi
382+
*.msix
383+
*.msm
384+
*.msp
385+
386+
# JetBrains Rider
387+
.idea/
388+
*.sln.iml

nuget.config

-18
This file was deleted.

src/TioSharp/TioSharp.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public TioApi(string backend = "https://tio.run/cgi-bin/run/api/", string json =
2323

2424
public void RefreshLanguages()
2525
{
26-
List<string> newList = new List<string>();
26+
List<string> newList = new();
2727

2828
JObject file = JObject.Parse(new WebClient().DownloadString(Json));
2929

@@ -38,7 +38,7 @@ public void RefreshLanguages()
3838

3939
public async Task RefreshLanguagesAsync()
4040
{
41-
List<string> newList = new List<string>();
41+
List<string> newList = new();
4242

4343
JObject file = JObject.Parse(await new WebClient().DownloadStringTaskAsync(new Uri(Json)));
4444

@@ -55,7 +55,7 @@ public async Task RefreshLanguagesAsync()
5555
// </summary>
5656
public byte[] CreateRequestData(string language, string code, string[] inputs = null, string[] cFlags = null, string[] options = null, string[] args = null)
5757
{
58-
Dictionary<string, string[]> strings = new Dictionary<string, string[]> {
58+
Dictionary<string, string[]> strings = new() {
5959
{ "lang", new[] { language } },
6060
{ ".code.tio", new[] { code } },
6161
{ ".input.tio", inputs != null? new[] { string.Join('\n', inputs) } : null },
@@ -64,7 +64,7 @@ public byte[] CreateRequestData(string language, string code, string[] inputs =
6464
{ "args", args }
6565
};
6666

67-
List<byte> bytes = new List<byte>();
67+
List<byte> bytes = new();
6868

6969
foreach (KeyValuePair<string, string[]> pair in strings)
7070
{
@@ -79,7 +79,7 @@ public byte[] CreateRequestData(string language, string code, string[] inputs =
7979
// </summary>
8080
public async Task<string> SendAsync(byte[] requestData)
8181
{
82-
HttpClient client = new HttpClient();
82+
HttpClient client = new();
8383
HttpResponseMessage response = await client.PostAsync("https://tio.run/cgi-bin/run/api/", new ByteArrayContent(requestData));
8484
response.EnsureSuccessStatusCode();
8585
byte[] responseBytes = await response.Content.ReadAsByteArrayAsync();

src/TiuSharpBot/Models/ScoreEntry.cs

-8
This file was deleted.

src/TiuSharpBot/Modules/GamesModule.cs

+10-28
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
using System;
1+
using Discord;
2+
using Discord.Addons.Interactive;
3+
using Discord.Commands;
4+
using Discord.WebSocket;
5+
using System;
26
using System.Collections.Generic;
37
using System.Linq;
48
using System.Text;
59
using System.Threading.Tasks;
6-
using Discord;
7-
using Discord.Addons.Interactive;
8-
using Discord.Commands;
9-
using Discord.WebSocket;
10-
using Microsoft.Extensions.Configuration;
11-
using MitsukuApi;
1210

13-
namespace RizalBot.Modules
11+
namespace TiuSharpBot.Modules
1412
{
1513
[Name("Games"), Summary("Play various games!")]
1614
public class GamesModule : InteractiveBase<SocketCommandContext>
1715
{
18-
private readonly CommandService _service;
19-
private readonly IConfigurationRoot _config;
20-
2116
private readonly string[] _hangmanGraphics =
2217
{
2318
@"‎‏‏‎‎‏‏‎‎ __ __
@@ -62,16 +57,10 @@ public class GamesModule : InteractiveBase<SocketCommandContext>
6257
__ | __ <:bottom2:808148053742977035>"
6358
};
6459

65-
public GamesModule(CommandService service, IConfigurationRoot config)
66-
{
67-
_service = service;
68-
_config = config;
69-
}
70-
7160
[Command("hangman"), Summary("Play hangman. You will be asked to set the prompt and the rest will try to answer.")]
7261
public async Task Hangman()
7362
{
74-
Criteria<SocketMessage> fromSourceUserDm = new Criteria<SocketMessage>();
63+
Criteria<SocketMessage> fromSourceUserDm = new();
7564
fromSourceUserDm.AddCriterion(new EnsureSourceUserCriterion());
7665
fromSourceUserDm.AddCriterion(new EnsureFromChannelCriterion(await Context.User.GetOrCreateDMChannelAsync()));
7766

@@ -101,7 +90,7 @@ public async Task Hangman()
10190
// Consistent capitalization
10291
string word = response.Content.ToLower();
10392
IUserMessage hangmanMessage = null;
104-
List<char> guessedLetters = new List<char>();
93+
List<char> guessedLetters = new();
10594
bool isWon = false;
10695

10796
await ReplyAsync("Starting game!");
@@ -112,7 +101,7 @@ public async Task Hangman()
112101
bool isAlreadyGuessed;
113102
do
114103
{
115-
StringBuilder message = new StringBuilder($"{hangmanGraphic}\n\n");
104+
StringBuilder message = new($"{hangmanGraphic}\n\n");
116105

117106
foreach (char c in word)
118107
{
@@ -178,14 +167,7 @@ await ReplyAsync("You have already tried that letter!",
178167
if (isWon) break;
179168
}
180169

181-
if (isWon)
182-
{
183-
await ReplyAsync($"Congratulations! You have guessed the word: `{word}`");
184-
}
185-
else
186-
{
187-
await ReplyAsync($"You lost! The word is: `{word}`");
188-
}
170+
await ReplyAsync(isWon ? $"Congratulations! You have guessed the word: `{word}`" : $"You lost! The word is: `{word}`");
189171
}
190172
}
191173
}

src/TiuSharpBot/Modules/HelpModule.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System.Linq;
2-
using System.Threading.Tasks;
3-
using Discord;
1+
using Discord;
42
using Discord.Commands;
53
using Microsoft.Extensions.Configuration;
4+
using System.Linq;
5+
using System.Threading.Tasks;
66

77
namespace TiuSharpBot.Modules
88
{

src/TiuSharpBot/Modules/MathModule.cs

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
1-
using System.Linq;
1+
using Discord.Commands;
2+
using System.Linq;
23
using System.Text;
34
using System.Threading.Tasks;
4-
using Discord.Commands;
55

66
namespace TiuSharpBot.Modules
77
{
88
[Name("Math"), Summary("Do some math I guess")]
99
public class MathModule : ModuleBase<SocketCommandContext>
1010
{
11-
[Command("multiply"), Summary("Get the product of two numbers.")]
12-
public async Task Multiply(int a, int b)
11+
[Command("multiply"), Summary("Get the product of two numbers.")]
12+
public async Task Multiply(int a, int b)
1313
{
1414
int product = a * b;
1515
await ReplyAsync($"The product of `{a} * {b}` is `{product}`.");
1616
}
1717

18-
[Command("addmany"), Summary("Get the sum of many numbers")]
19-
public async Task AddMany(params int[] numbers)
18+
[Command("addmany"), Summary("Get the sum of many numbers")]
19+
public async Task AddMany(params int[] numbers)
2020
{
2121
int sum = numbers.Sum();
2222
await ReplyAsync($"The sum of `{string.Join(", ", numbers)}` is `{sum}`.");
2323
}
2424

25-
[Command("goldbach"), Summary("Get all prime sum pairs of a given even integer.")]
26-
public async Task Goldbach([Summary("The number to evaluate.")]int num)
25+
[Command("goldbach"), Summary("Get all prime sum pairs of a given even integer.")]
26+
public async Task Goldbach([Summary("The number to evaluate.")] int num)
2727
{
28-
// Check all sum combinations and return the first one which both pairs are prime
29-
if (num % 2 == 0)
30-
{
31-
StringBuilder sb = new StringBuilder();
32-
sb.AppendLine("The pairs are:");
28+
// Check all sum combinations and return the first one which both pairs are prime
29+
if (num % 2 == 0)
30+
{
31+
StringBuilder sb = new();
32+
sb.AppendLine("The pairs are:");
3333
for (int i = 2, j = num - i; j >= 2 && i <= num / 2; i++, j--)
34-
{
35-
if (IsPrime(i) && IsPrime(j))
36-
{
37-
sb.AppendLine($"{num} = {i} + {j}");
38-
}
39-
}
34+
{
35+
if (IsPrime(i) && IsPrime(j))
36+
{
37+
sb.AppendLine($"{num} = {i} + {j}");
38+
}
39+
}
4040

4141
await ReplyAsync(sb.ToString());
42-
}
43-
else
44-
{
45-
await ReplyAsync("Please revise. Your number is not even.");
46-
}
42+
}
43+
else
44+
{
45+
await ReplyAsync("Please revise. Your number is not even.");
46+
}
4747
}
4848

49-
private bool IsPrime(int n)
49+
private static bool IsPrime(int n)
5050
{
51-
for (int j = 2; j < n / 2; j++)
52-
{
53-
if (n % j == 0)
54-
{
55-
return false;
56-
}
57-
}
58-
return true;
51+
for (int j = 2; j < n / 2; j++)
52+
{
53+
if (n % j == 0)
54+
{
55+
return false;
56+
}
57+
}
58+
return true;
5959
}
6060
}
6161
}

0 commit comments

Comments
 (0)