diff --git a/src/NadekoBot/Modules/Utility/Commands/PatreonCommands.cs b/src/NadekoBot/Modules/Utility/Commands/PatreonCommands.cs new file mode 100644 index 00000000..b347330f --- /dev/null +++ b/src/NadekoBot/Modules/Utility/Commands/PatreonCommands.cs @@ -0,0 +1,78 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using Discord.Commands; +using Discord; +using NadekoBot.Attributes; +using NadekoBot.Modules.Utility.Models; +using Newtonsoft.Json; + +namespace NadekoBot.Modules.Utility +{ + public partial class Utility + { + //[Group] + //public class PatreonCommands : NadekoSubmodule + //{ + // [NadekoCommand, Usage, Description, Aliases] + // [RequireContext(ContextType.Guild)] + // public async Task ClaimPatreonRewards([Remainder] string arg) + // { + // var pledges = await GetPledges2(); + // } + + // private static async Task GetPledges() + // { + // var pledges = new List(); + // using (var http = new HttpClient()) + // { + // http.DefaultRequestHeaders.Clear(); + // http.DefaultRequestHeaders.Add("Authorization", "Bearer " + NadekoBot.Credentials.PatreonAccessToken); + // var data = new PatreonData() + // { + // Links = new Links() + // { + // Next = "https://api.patreon.com/oauth2/api/campaigns/334038/pledges" + // } + // }; + // do + // { + // var res = + // await http.GetStringAsync(data.Links.Next) + // .ConfigureAwait(false); + // data = JsonConvert.DeserializeObject(res); + // pledges.AddRange(data.Data); + // } while (!string.IsNullOrWhiteSpace(data.Links.Next)); + // } + // return pledges.Where(x => string.IsNullOrWhiteSpace(x.Attributes.declined_since)).ToArray(); + // } + + // private static async Task GetPledges2() + // { + // var pledges = new List(); + // using (var http = new HttpClient()) + // { + // http.DefaultRequestHeaders.Clear(); + // http.DefaultRequestHeaders.Add("Authorization", "Bearer " + NadekoBot.Credentials.PatreonAccessToken); + // var data = new PatreonData() + // { + // Links = new Links() + // { + // Next = "https://api.patreon.com/oauth2/api/current_user/campaigns?include=pledges" + // } + // }; + // do + // { + // var res = + // await http.GetStringAsync(data.Links.Next) + // .ConfigureAwait(false); + // data = JsonConvert.DeserializeObject(res); + // pledges.AddRange(data.Data); + // } while (!string.IsNullOrWhiteSpace(data.Links.Next)); + // } + // return pledges.Where(x => string.IsNullOrWhiteSpace(x.Attributes.declined_since)).ToArray(); + // } + //} + } +} diff --git a/src/NadekoBot/Modules/Utility/Models/PatreonData.cs b/src/NadekoBot/Modules/Utility/Models/PatreonData.cs new file mode 100644 index 00000000..381666e8 --- /dev/null +++ b/src/NadekoBot/Modules/Utility/Models/PatreonData.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Modules.Utility.Models +{ + + public class PatreonData + { + public Pledge[] Data { get; set; } + public Links Links { get; set; } + } + + public class Attributes + { + public int amount_cents { get; set; } + public string created_at { get; set; } + public string declined_since { get; set; } + public bool is_twitch_pledge { get; set; } + public bool patron_pays_fees { get; set; } + public int pledge_cap_cents { get; set; } + } + + public class Pledge + { + public Attributes Attributes { get; set; } + public int Id { get; set; } + } + + public class Links + { + public string First { get; set; } + public string Next { get; set; } + } +} diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index c91f93cb..d1bef121 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -2081,6 +2081,15 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to You've already joined this race!. + /// + public static string gambling_animal_race_already_in { + get { + return ResourceManager.GetString("gambling_animal_race_already_in", resourceCulture); + } + } + /// /// Looks up a localized string similar to Animal Race is already running.. /// diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index a1674f52..9af8d41f 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -1218,6 +1218,9 @@ Don't forget to leave your discord name or id in the message. Animal Race is already running. + + You've already joined this race! + Total: {0} Average: {1} diff --git a/src/NadekoBot/Services/IBotCredentials.cs b/src/NadekoBot/Services/IBotCredentials.cs index a03c6db3..63bea8b8 100644 --- a/src/NadekoBot/Services/IBotCredentials.cs +++ b/src/NadekoBot/Services/IBotCredentials.cs @@ -7,13 +7,13 @@ namespace NadekoBot.Services public interface IBotCredentials { ulong ClientId { get; } - ulong BotId { get; } string Token { get; } string GoogleApiKey { get; } ImmutableHashSet OwnerIds { get; } string MashapeKey { get; } string LoLApiKey { get; } + string PatreonAccessToken { get; } DBConfig Db { get; } diff --git a/src/NadekoBot/Services/Impl/BotCredentials.cs b/src/NadekoBot/Services/Impl/BotCredentials.cs index 56851762..a0220778 100644 --- a/src/NadekoBot/Services/Impl/BotCredentials.cs +++ b/src/NadekoBot/Services/Impl/BotCredentials.cs @@ -5,7 +5,6 @@ using Discord; using System.Linq; using NLog; using Microsoft.Extensions.Configuration; -using System.Collections.Generic; using System.Collections.Immutable; namespace NadekoBot.Services.Impl @@ -15,7 +14,6 @@ namespace NadekoBot.Services.Impl private Logger _log; public ulong ClientId { get; } - public ulong BotId { get; } public string GoogleApiKey { get; } @@ -44,6 +42,7 @@ namespace NadekoBot.Services.Impl public string CarbonKey { get; } public string credsFileName { get; } = Path.Combine(Directory.GetCurrentDirectory(), "credentials.json"); + public string PatreonAccessToken { get; } public BotCredentials() { @@ -68,6 +67,7 @@ namespace NadekoBot.Services.Impl GoogleApiKey = data[nameof(GoogleApiKey)]; MashapeKey = data[nameof(MashapeKey)]; OsuApiKey = data[nameof(OsuApiKey)]; + PatreonAccessToken = data[nameof(PatreonAccessToken)]; int ts = 1; int.TryParse(data[nameof(TotalShards)], out ts); @@ -109,6 +109,7 @@ namespace NadekoBot.Services.Impl public string CarbonKey { get; set; } = ""; public DBConfig Db { get; set; } = new DBConfig("sqlite", "Filename=./data/NadekoBot.db"); public int TotalShards { get; set; } = 1; + public string PatreonAccessToken { get; set; } = ""; } private class DbModel diff --git a/src/NadekoBot/credentials_example.json b/src/NadekoBot/credentials_example.json index 240f9029..912b452a 100644 --- a/src/NadekoBot/credentials_example.json +++ b/src/NadekoBot/credentials_example.json @@ -14,5 +14,6 @@ "Type": "sqlite", "ConnectionString": "Filename=./data/NadekoBot.db" }, - "TotalShards": 1 + "TotalShards": 1, + "PatreonAccessToken": "" } \ No newline at end of file