Skip to content

Commit d7454b5

Browse files
committed
Issue4: Removed obsolete slides API and removed configuration for it.
1 parent 4147111 commit d7454b5

6 files changed

+83
-344
lines changed

Beef/Application.cs

+16-31
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
namespace Beef {
1414
class Application : ProfileInfoProvider, MmrListener, TwitchLiveListener {
15-
private readonly String _version = "2.0.0";
15+
private readonly String _version = "2.1.0";
1616
private BeefConfig _config;
1717
private String _botPrefix;
1818
private String _beefCommand;
1919
private BeefUserConfigManager _userManager;
20-
private PresentationManager _presentationManager;
20+
private LadderManager _ladderManager;
2121
private String[] _leaderRoles;
2222
private String[] _dynamicChannels; // Names of channels that should be cloned to maintain 1 empty at all times
2323
private bool _dynamicVoiceChannelsEnabled = false;
@@ -48,12 +48,7 @@ public Application(BeefConfig config, String exePath) {
4848
_leaderRoles = config.LeaderRoles;
4949
_dynamicChannels = config.DynamicChannels;
5050

51-
_presentationManager = new PresentationManager(
52-
_config.GoogleApiPresentationId,
53-
_config.GoogleApiCredentialFile,
54-
_config.GoogleApiApplicationName,
55-
_exePath + "/Backups");
56-
_presentationManager.Initialize();
51+
_ladderManager = new LadderManager(_exePath + "/Backups");
5752
_userManager = new BeefUserConfigManager(_exePath + "/Users");
5853

5954
if (SynchronizationContext.Current == null || !(SynchronizationContext.Current is DispatcherSynchronizationContext)) {
@@ -73,7 +68,7 @@ public Application(BeefConfig config, String exePath) {
7368
}
7469

7570
// Start the API
76-
_apiServer = new ApiServer(_exePath + "/BeefApiConfig.json", SynchronizationContext.Current, _presentationManager, _userManager);
71+
_apiServer = new ApiServer(_exePath + "/BeefApiConfig.json", SynchronizationContext.Current, _ladderManager, _userManager);
7772
_apiServer.Start();
7873
}
7974

@@ -212,11 +207,6 @@ private void HandleCommand(SocketMessage userInput) {
212207
ISocketMessageChannel channel = userInput.Channel;
213208
ErrorCode code = ErrorCode.CommandNotRecognized;
214209

215-
if (!_presentationManager.Authenticate().Ok()) {
216-
Console.WriteLine("Could not authenticate.");
217-
return;
218-
}
219-
220210
if (arguments.Length == 1) {
221211
// Just print the ladder link
222212
code = ErrorCode.Success;
@@ -502,11 +492,11 @@ private void HandleCommand(SocketMessage userInput) {
502492
if (!int.TryParse(losingPlayer, out losingRank)) losingRank = -1;
503493

504494
if (winningRank != -1 && losingRank != -1) {
505-
code = _presentationManager.ReportWin(winningRank, losingRank);
495+
code = _ladderManager.ReportWin(winningRank, losingRank);
506496
} else if (winningRank == -1 && losingRank != -1) {
507-
code = _presentationManager.ReportWin(winningPlayer, losingRank);
497+
code = _ladderManager.ReportWin(winningPlayer, losingRank);
508498
} else {
509-
code = _presentationManager.ReportWin(winningPlayer, losingPlayer);
499+
code = _ladderManager.ReportWin(winningPlayer, losingPlayer);
510500
}
511501

512502
if (code.Ok())
@@ -524,7 +514,7 @@ private void HandleCommand(SocketMessage userInput) {
524514

525515
if (rank != -1) {
526516
BeefEntry existingPlayer;
527-
code = _presentationManager.RenamePlayer(rank - 1, newName, out existingPlayer);
517+
code = _ladderManager.RenamePlayer(rank - 1, newName, out existingPlayer);
528518

529519
if (existingPlayer != null) {
530520
playerOrRankToRename = existingPlayer.PlayerName;
@@ -533,7 +523,7 @@ private void HandleCommand(SocketMessage userInput) {
533523
}
534524
}
535525
} else {
536-
code = _presentationManager.RenamePlayer(playerOrRankToRename, newName);
526+
code = _ladderManager.RenamePlayer(playerOrRankToRename, newName);
537527
}
538528

539529
if (code.Ok()) {
@@ -556,7 +546,7 @@ private void HandleCommand(SocketMessage userInput) {
556546

557547
BeefEntry player1 = null;
558548
BeefEntry player2 = null;
559-
code = _presentationManager.SwitchPlayers(playerOrRank1, playerOrRank2, out player1, out player2);
549+
code = _ladderManager.SwitchPlayers(playerOrRank1, playerOrRank2, out player1, out player2);
560550

561551
if (code.Ok()) {
562552
MessageChannel(channel, "**" + player1.PlayerName + "** has been switched with **" + player2.PlayerName + "**").GetAwaiter().GetResult();
@@ -592,19 +582,19 @@ private void HandleCommand(SocketMessage userInput) {
592582

593583
if (rank != -1) {
594584
BeefEntry removedPlayerEntry;
595-
code = _presentationManager.RemovePlayer(rank - 1, out removedPlayerEntry);
585+
code = _ladderManager.RemovePlayer(rank - 1, out removedPlayerEntry);
596586

597587
if (code.Ok())
598588
playerToRemove = removedPlayerEntry.PlayerName;
599589
} else {
600-
code = _presentationManager.RemovePlayer(playerToRemove);
590+
code = _ladderManager.RemovePlayer(playerToRemove);
601591
}
602592

603593
if (code.Ok()) {
604594
MessageChannel(channel, "Removed **" + playerToRemove + "** from the ladder.").GetAwaiter().GetResult();
605595
}
606596
} else if (arguments[1] == "bracket" || arguments[1] == "list" || arguments[1] == "ladder") {
607-
List<BeefEntry> entries = _presentationManager.ReadBracket();
597+
List<BeefEntry> entries = _ladderManager.ReadBracket();
608598

609599
if (entries.Count == 0)
610600
code = ErrorCode.CouldNotReadTheLadder;
@@ -643,7 +633,7 @@ private void HandleCommand(SocketMessage userInput) {
643633
return;
644634
}
645635

646-
code = _presentationManager.Undo();
636+
code = _ladderManager.Undo();
647637
if (code.Ok()) {
648638
MessageChannel(channel, "Undid what you should have done undid 10 minutes ago.").GetAwaiter().GetResult();
649639
}
@@ -658,7 +648,7 @@ private void HandleCommand(SocketMessage userInput) {
658648
code = ErrorCode.Success;
659649

660650
String help = "";
661-
help += "The Beef ladder is maintained on Google Docs as a Slide presentation. This bot makes it more convenient to update it. Each Beef command is prefixed with \"%beef%\".\n";
651+
help += "This bot maintains the current Beef Ladder and provides commands to update it. It also can monitor twitch streams and notify when they go live and read MMR of players that are linked automatically. Each Beef command is prefixed with \"%beef%\".\n";
662652
help += "Note, commands that have parameters in them surrounded in [] means that parameter is optional. As an example \"all\" is a common suffix you can add to make a command print to the chat instead of whispering the response to you.\n";
663653
help += "The following commands are available:\n";
664654
help += "\t **%beef%** - Prints the link to the ladder.\n";
@@ -879,11 +869,6 @@ public List<ProfileInfo> GetLadderUsers() {
879869

880870
public void OnMmrRead(List<Tuple<ProfileInfo, LadderInfo>> mmrList) {
881871
_mainContext.Post((_) => {
882-
if (!_presentationManager.Authenticate().Ok()) {
883-
Console.WriteLine("Could not authenticate when reading MMR.");
884-
return;
885-
}
886-
887872
// Make the list a dictionary so we can quickly lookup MMR
888873
var profileIdToMaxMmrDict = new Dictionary<String, Tuple<ProfileInfo, LadderInfo>>();
889874
foreach (Tuple<ProfileInfo, LadderInfo> entry in mmrList) {
@@ -919,7 +904,7 @@ public void OnMmrRead(List<Tuple<ProfileInfo, LadderInfo>> mmrList) {
919904
Console.WriteLine("Warning: User " + user.BeefName + " already exists in the profileIdToMaxMmrDict!");
920905
}
921906

922-
_presentationManager.UpdateMmrDictionary(profileIdToMaxMmrDict);
907+
_ladderManager.UpdateMmrDictionary(profileIdToMaxMmrDict);
923908

924909
Console.WriteLine($"Read MMR. Users:");
925910
foreach (Tuple<ProfileInfo, LadderInfo> entry in mmrList) {

Beef/Beef.csproj

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Discord.Net" Version="3.8.1" />
14-
<PackageReference Include="Google.Apis" Version="1.57.0" />
15-
<PackageReference Include="Google.Apis.Auth" Version="1.57.0" />
16-
<PackageReference Include="Google.Apis.Slides.v1" Version="1.57.0.2759" />
1714
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
1815
</ItemGroup>
1916

Beef/BeefApi/ApiServer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public class ApiServer {
1818
private String _configFilePath;
1919
private SynchronizationContext _mainContext;
2020
private BeefUserConfigManager _beefUserManager;
21-
private PresentationManager _ladderManager;
21+
private LadderManager _ladderManager;
2222
private WebApplication _application;
2323
private Thread _thread;
2424
private SynchronizationContext _threadContext;
2525
private int _eventSocket; // set from the config file
2626
private List<Socket> _eventClients = new List<Socket>();
2727
private object _lock = new object();
2828

29-
public ApiServer(String configFilePath, SynchronizationContext mainContext, PresentationManager ladderManager, BeefUserConfigManager beefUserManager) {
29+
public ApiServer(String configFilePath, SynchronizationContext mainContext, LadderManager ladderManager, BeefUserConfigManager beefUserManager) {
3030
_configFilePath = configFilePath;
3131
_mainContext = mainContext;
3232
_ladderManager = ladderManager;

Beef/BeefConfig.cs

+42-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Beef {
77
/// </summary>
88
public class BeefConfig {
99
// This is the current version and should always be incremented when changing the config file format.
10-
public static int BeefConfigVersion = 4;
10+
public static int BeefConfigVersion = 5;
1111

1212
// Version
1313
public int Version { get; set; } = BeefConfigVersion; // This identifies the version of the config file.
@@ -19,10 +19,7 @@ public class BeefConfig {
1919
public String[] LeaderRoles { get; set; } = new String[] { "ExampleRole1", "ExampleRole2" };
2020
public String[] DynamicChannels { get; set; } = new String[] { "Teams" }; // Names of channels that there should always be exactly 1 empty of
2121

22-
// Presentation Stuff
23-
public String GoogleApiCredentialFile { get; set; } = "credentials.json";
24-
public String GoogleApiApplicationName { get; set; } = "";
25-
public String GoogleApiPresentationId { get; set; } = ""; // This is the Google doc IDs of the presentation.
22+
// Ladder Link
2623
public String BeefLadderLink { get; set; } = ""; // This is the ladders that can be viewed by users.
2724

2825
// Config for reading MMRs using the battle.net API
@@ -51,6 +48,46 @@ public static BeefConfig CreateDefault() {
5148
/// Keeps track of settings for the config file. This class needs to exactly match the Config.json.example file so that it can be
5249
/// deserialized into it. So if you rename or change parameters here, you must upgrade the config file format as well.
5350
/// </summary>
51+
///
52+
public class BeefConfigV4 {
53+
// This is the current version and should always be incremented when changing the config file format.
54+
public static int BeefConfigVersion = 4;
55+
56+
// Version
57+
public int Version { get; set; } = BeefConfigVersion; // This identifies the version of the config file.
58+
59+
// Discord stuff
60+
public String DiscordBotToken { get; set; } = "";
61+
public String BotPrefix { get; set; } = ".";
62+
public String BeefCommand { get; set; } = "beef";
63+
public String[] LeaderRoles { get; set; } = new String[] { "ExampleRole1", "ExampleRole2" };
64+
public String[] DynamicChannels { get; set; } = new String[] { "Teams" }; // Names of channels that there should always be exactly 1 empty of
65+
66+
// Presentation Stuff
67+
public String GoogleApiCredentialFile { get; set; } = "credentials.json";
68+
public String GoogleApiApplicationName { get; set; } = "";
69+
public String GoogleApiPresentationId { get; set; } = ""; // This is the Google doc IDs of the presentation.
70+
public String BeefLadderLink { get; set; } = ""; // This is the ladders that can be viewed by users.
71+
72+
// Config for reading MMRs using the battle.net API
73+
public ReaderConfig MmrReaderConfig { get; set; } = ReaderConfig.CreateDefault();
74+
75+
// Config for interacting with Twitch
76+
public TwitchConfig TwitchConfig {get; set; } = new TwitchConfig();
77+
78+
/// <summary>
79+
/// Creates a ReaderConfig with default settings.
80+
/// </summary>
81+
/// <returns>Returns the created config.</returns>
82+
public static BeefConfig CreateDefault() {
83+
// Fill out the default settings and version
84+
BeefConfig config = new BeefConfig();
85+
86+
// The credentials are left blank and need to be filled out after
87+
return config;
88+
}
89+
}
90+
5491
public class BeefConfigV3 {
5592
// This is the current version and should always be incremented when changing the config file format.
5693
public static int BeefConfigVersion = 3;

0 commit comments

Comments
 (0)