Only a few things with permissions left, and prefixes
This commit is contained in:
@@ -15,10 +15,10 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration : NadekoTopLevelModule
|
||||
{
|
||||
private IGuild _nadekoSupportServer;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly AdministrationService _admin;
|
||||
|
||||
public Administration(DbHandler db, AdministrationService admin)
|
||||
public Administration(DbService db, AdministrationService admin)
|
||||
{
|
||||
_db = db;
|
||||
_admin = admin;
|
||||
|
@@ -14,10 +14,10 @@ namespace NadekoBot.Modules.Administration
|
||||
[Group]
|
||||
public class AutoAssignRoleCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly AutoAssignRoleService _service;
|
||||
|
||||
public AutoAssignRoleCommands(AutoAssignRoleService service, DbHandler db)
|
||||
public AutoAssignRoleCommands(AutoAssignRoleService service, DbService db)
|
||||
{
|
||||
_db = db;
|
||||
_service = service;
|
||||
|
@@ -12,10 +12,10 @@ namespace NadekoBot.Modules.Administration
|
||||
[Group]
|
||||
public class GameChannelCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly GameVoiceChannelService _service;
|
||||
|
||||
public GameChannelCommands(GameVoiceChannelService service, DbHandler db)
|
||||
public GameChannelCommands(GameVoiceChannelService service, DbService db)
|
||||
{
|
||||
_db = db;
|
||||
_service = service;
|
||||
|
@@ -22,9 +22,9 @@ namespace NadekoBot.Modules.Administration
|
||||
public class Migration : NadekoSubmodule
|
||||
{
|
||||
private const int CURRENT_VERSION = 1;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public Migration(DbHandler db)
|
||||
public Migration(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
@@ -14,9 +14,9 @@ namespace NadekoBot.Modules.Administration
|
||||
public class MuteCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly MuteService _service;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public MuteCommands(MuteService service, DbHandler db)
|
||||
public MuteCommands(MuteService service, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
|
@@ -14,10 +14,10 @@ namespace NadekoBot.Modules.Administration
|
||||
public class PlayingRotateCommands : NadekoSubmodule
|
||||
{
|
||||
private static readonly object _locker = new object();
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly PlayingRotateService _service;
|
||||
|
||||
public PlayingRotateCommands(PlayingRotateService service, DbHandler db)
|
||||
public PlayingRotateCommands(PlayingRotateService service, DbService db)
|
||||
{
|
||||
_db = db;
|
||||
_service = service;
|
||||
|
@@ -19,9 +19,9 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
private readonly ProtectionService _service;
|
||||
private readonly MuteService _mute;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public ProtectionCommands(ProtectionService service, MuteService mute, DbHandler db)
|
||||
public ProtectionCommands(ProtectionService service, MuteService mute, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_mute = mute;
|
||||
|
@@ -15,12 +15,12 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class RatelimitCommands : NadekoSubmodule
|
||||
public class SlowModeCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly RatelimitService _service;
|
||||
private readonly DbHandler _db;
|
||||
private readonly SlowmodeService _service;
|
||||
private readonly DbService _db;
|
||||
|
||||
public RatelimitCommands(RatelimitService service, DbHandler db)
|
||||
public SlowModeCommands(SlowmodeService service, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
|
@@ -18,9 +18,9 @@ namespace NadekoBot.Modules.Administration
|
||||
[Group]
|
||||
public class SelfAssignedRolesCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public SelfAssignedRolesCommands(DbHandler db)
|
||||
public SelfAssignedRolesCommands(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
@@ -21,14 +21,14 @@ namespace NadekoBot.Modules.Administration
|
||||
[Group]
|
||||
public class SelfCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
private static readonly object _locker = new object();
|
||||
private readonly SelfService _service;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly IImagesService _images;
|
||||
|
||||
public SelfCommands(DbHandler db, SelfService service, DiscordShardedClient client,
|
||||
public SelfCommands(DbService db, SelfService service, DiscordShardedClient client,
|
||||
IImagesService images)
|
||||
{
|
||||
_db = db;
|
||||
@@ -203,64 +203,6 @@ namespace NadekoBot.Modules.Administration
|
||||
await ReplyConfirmLocalized("fwall_stop").ConfigureAwait(false);
|
||||
|
||||
}
|
||||
|
||||
//todo dm forwarding
|
||||
//public async Task HandleDmForwarding(IUserMessage msg, ImmutableArray<AsyncLazy<IDMChannel>> ownerChannels)
|
||||
//{
|
||||
// if (_service.ForwardDMs && ownerChannels.Length > 0)
|
||||
// {
|
||||
// var title = _strings.GetText("dm_from",
|
||||
// NadekoBot.Localization.DefaultCultureInfo,
|
||||
// typeof(Administration).Name.ToLowerInvariant()) +
|
||||
// $" [{msg.Author}]({msg.Author.Id})";
|
||||
|
||||
// var attachamentsTxt = GetTextStatic("attachments",
|
||||
// NadekoBot.Localization.DefaultCultureInfo,
|
||||
// typeof(Administration).Name.ToLowerInvariant());
|
||||
|
||||
// var toSend = msg.Content;
|
||||
|
||||
// if (msg.Attachments.Count > 0)
|
||||
// {
|
||||
// toSend += $"\n\n{Format.Code(attachamentsTxt)}:\n" +
|
||||
// string.Join("\n", msg.Attachments.Select(a => a.ProxyUrl));
|
||||
// }
|
||||
|
||||
// if (_service.ForwardDMsToAllOwners)
|
||||
// {
|
||||
// var allOwnerChannels = await Task.WhenAll(ownerChannels
|
||||
// .Select(x => x.Value))
|
||||
// .ConfigureAwait(false);
|
||||
|
||||
// foreach (var ownerCh in allOwnerChannels.Where(ch => ch.Recipient.Id != msg.Author.Id))
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// await ownerCh.SendConfirmAsync(title, toSend).ConfigureAwait(false);
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// _log.Warn("Can't contact owner with id {0}", ownerCh.Recipient.Id);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var firstOwnerChannel = await ownerChannels[0];
|
||||
// if (firstOwnerChannel.Recipient.Id != msg.Author.Id)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// await firstOwnerChannel.SendConfirmAsync(title, toSend).ConfigureAwait(false);
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// // ignored
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
|
@@ -14,9 +14,9 @@ namespace NadekoBot.Modules.Administration
|
||||
public class ServerGreetCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly GreetSettingsService _greetService;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public ServerGreetCommands(GreetSettingsService greetService, DbHandler db)
|
||||
public ServerGreetCommands(GreetSettingsService greetService, DbService db)
|
||||
{
|
||||
_greetService = greetService;
|
||||
_db = db;
|
||||
|
@@ -19,10 +19,10 @@ namespace NadekoBot.Modules.Administration
|
||||
[Group]
|
||||
public class UserPunishCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly MuteService _muteService;
|
||||
|
||||
public UserPunishCommands(DbHandler db, MuteService muteService)
|
||||
public UserPunishCommands(DbService db, MuteService muteService)
|
||||
{
|
||||
_db = db;
|
||||
_muteService = muteService;
|
||||
|
@@ -19,9 +19,9 @@ namespace NadekoBot.Modules.Administration
|
||||
public class VcRoleCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly VcRoleService _service;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public VcRoleCommands(VcRoleService service, DbHandler db)
|
||||
public VcRoleCommands(VcRoleService service, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
@@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Administration
|
||||
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||
[RequireUserPermission(GuildPermission.ManageChannels)]
|
||||
[RequireBotPermission(GuildPermission.ManageRoles)]
|
||||
//todo discord.net [RequireBotPermission(GuildPermission.ManageChannels)]
|
||||
//todo 999 discord.net [RequireBotPermission(GuildPermission.ManageChannels)]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task VcRole([Remainder]IRole role = null)
|
||||
{
|
||||
|
@@ -18,9 +18,9 @@ namespace NadekoBot.Modules.Administration
|
||||
public class VoicePlusTextCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly VplusTService _service;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public VoicePlusTextCommands(VplusTService service, DbHandler db)
|
||||
public VoicePlusTextCommands(VplusTService service, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
|
@@ -15,11 +15,11 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
public class CustomReactions : NadekoTopLevelModule
|
||||
{
|
||||
private readonly IBotCredentials _creds;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly CustomReactionsService _crs;
|
||||
private readonly DiscordShardedClient _client;
|
||||
|
||||
public CustomReactions(IBotCredentials creds, DbHandler db, CustomReactionsService crs,
|
||||
public CustomReactions(IBotCredentials creds, DbService db, CustomReactionsService crs,
|
||||
DiscordShardedClient client)
|
||||
{
|
||||
_creds = creds;
|
||||
@@ -239,7 +239,7 @@ namespace NadekoBot.Modules.CustomReactions
|
||||
if ((toDelete.GuildId == null || toDelete.GuildId == 0) && Context.Guild == null)
|
||||
{
|
||||
uow.CustomReactions.Remove(toDelete);
|
||||
//todo i can dramatically improve performance of this, if Ids are ordered.
|
||||
//todo 91 i can dramatically improve performance of this, if Ids are ordered.
|
||||
_crs.GlobalReactions = _crs.GlobalReactions.Where(cr => cr?.Id != toDelete.Id).ToArray();
|
||||
success = true;
|
||||
}
|
||||
|
@@ -21,16 +21,16 @@ namespace NadekoBot.Modules.Gambling
|
||||
public class AnimalRacing : NadekoSubmodule
|
||||
{
|
||||
private readonly BotConfig _bc;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DiscordShardedClient _client;
|
||||
|
||||
|
||||
public static ConcurrentDictionary<ulong, AnimalRace> AnimalRaces { get; } = new ConcurrentDictionary<ulong, AnimalRace>();
|
||||
|
||||
public AnimalRacing(BotConfig bc, CurrencyHandler ch, DiscordShardedClient client)
|
||||
public AnimalRacing(BotConfig bc, CurrencyService cs, DiscordShardedClient client)
|
||||
{
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
public async Task Race()
|
||||
{
|
||||
var ar = new AnimalRace(Context.Guild.Id, (ITextChannel)Context.Channel, Prefix,
|
||||
_bc, _ch, _client,_localization, _strings);
|
||||
_bc, _cs, _client,_localization, _strings);
|
||||
|
||||
if (ar.Fail)
|
||||
await ReplyErrorLocalized("race_failed_starting").ConfigureAwait(false);
|
||||
@@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
await ar.JoinRace(Context.User as IGuildUser, amount);
|
||||
}
|
||||
|
||||
//todo needs to be completely isolated, shouldn't use any services in the constructor,
|
||||
//todo 85 needs to be completely isolated, shouldn't use any services in the constructor,
|
||||
//then move the rest either to the module itself, or the service
|
||||
public class AnimalRace
|
||||
{
|
||||
@@ -81,7 +81,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
private readonly ITextChannel _raceChannel;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly ILocalization _localization;
|
||||
private readonly NadekoStrings _strings;
|
||||
@@ -89,12 +89,12 @@ namespace NadekoBot.Modules.Gambling
|
||||
public bool Started { get; private set; }
|
||||
|
||||
public AnimalRace(ulong serverId, ITextChannel channel, string prefix, BotConfig bc,
|
||||
CurrencyHandler ch, DiscordShardedClient client, ILocalization localization,
|
||||
CurrencyService cs, DiscordShardedClient client, ILocalization localization,
|
||||
NadekoStrings strings)
|
||||
{
|
||||
_prefix = prefix;
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_serverId = serverId;
|
||||
_raceChannel = channel;
|
||||
@@ -144,7 +144,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
var p = _participants.FirstOrDefault();
|
||||
|
||||
if (p != null && p.AmountBet > 0)
|
||||
await _ch.AddCurrencyAsync(p.User, "BetRace", p.AmountBet, false).ConfigureAwait(false);
|
||||
await _cs.AddAsync(p.User, "BetRace", p.AmountBet, false).ConfigureAwait(false);
|
||||
End();
|
||||
return;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
var wonAmount = winner.AmountBet * (_participants.Count - 1);
|
||||
|
||||
await _ch.AddCurrencyAsync(winner.User, "Won a Race", wonAmount, true)
|
||||
await _cs.AddAsync(winner.User, "Won a Race", wonAmount, true)
|
||||
.ConfigureAwait(false);
|
||||
await _raceChannel.SendConfirmAsync(GetText("animal_race"),
|
||||
Format.Bold(GetText("animal_race_won_money", winner.User.Mention,
|
||||
@@ -287,7 +287,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
return;
|
||||
}
|
||||
if (amount > 0)
|
||||
if (!await _ch.RemoveCurrencyAsync(u, "BetRace", amount, false).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(u, "BetRace", amount, false).ConfigureAwait(false))
|
||||
{
|
||||
await _raceChannel.SendErrorAsync(GetText("not_enough", _bc.CurrencySign)).ConfigureAwait(false);
|
||||
return;
|
||||
|
@@ -36,13 +36,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
private string _secretCode = string.Empty;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
public CurrencyEvents(DiscordShardedClient client, BotConfig bc, CurrencyHandler ch)
|
||||
public CurrencyEvents(DiscordShardedClient client, BotConfig bc, CurrencyService cs)
|
||||
{
|
||||
_client = client;
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@@ -111,7 +111,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
await _ch.AddCurrencyAsync(arg.Author, "Sneaky Game Event", 100, false)
|
||||
await _cs.AddAsync(arg.Author, "Sneaky Game Event", 100, false)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
try { await arg.DeleteAsync(new RequestOptions() { RetryMode = RetryMode.AlwaysFail }).ConfigureAwait(false); }
|
||||
@@ -137,7 +137,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
desc, footer: footer)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await new FlowerReactionEvent(_client, _ch).Start(msg, context, amount);
|
||||
await new FlowerReactionEvent(_client, _cs).Start(msg, context, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,18 +152,18 @@ namespace NadekoBot.Modules.Gambling
|
||||
private readonly ConcurrentHashSet<ulong> _flowerReactionAwardedUsers = new ConcurrentHashSet<ulong>();
|
||||
private readonly Logger _log;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
private IUserMessage StartingMessage { get; set; }
|
||||
|
||||
private CancellationTokenSource Source { get; }
|
||||
private CancellationToken CancelToken { get; }
|
||||
|
||||
public FlowerReactionEvent(DiscordShardedClient client, CurrencyHandler ch)
|
||||
public FlowerReactionEvent(DiscordShardedClient client, CurrencyService cs)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_client = client;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
Source = new CancellationTokenSource();
|
||||
CancelToken = Source.Token;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
if (r.Emote.Name == "🌸" && r.User.IsSpecified && ((DateTime.UtcNow - r.User.Value.CreatedAt).TotalDays > 5) && _flowerReactionAwardedUsers.Add(r.User.Value.Id))
|
||||
{
|
||||
await _ch.AddCurrencyAsync(r.User.Value, "Flower Reaction Event", amount, false)
|
||||
await _cs.AddAsync(r.User.Value, "Flower Reaction Event", amount, false)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
@@ -220,8 +220,8 @@ namespace NadekoBot.Modules.Gambling
|
||||
if (num == 10)
|
||||
{
|
||||
var images = _images.Dice;
|
||||
using (var imgOneStream = images[1].Value.ToStream())
|
||||
using (var imgZeroStream = images[0].Value.ToStream())
|
||||
using (var imgOneStream = images[1].ToStream())
|
||||
using (var imgZeroStream = images[0].ToStream())
|
||||
{
|
||||
Image imgOne = new Image(imgOneStream);
|
||||
Image imgZero = new Image(imgZeroStream);
|
||||
@@ -229,7 +229,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
return new[] { imgOne, imgZero }.Merge();
|
||||
}
|
||||
}
|
||||
using (var die = _images.Dice[num].Value.ToStream())
|
||||
using (var die = _images.Dice[num].ToStream())
|
||||
{
|
||||
return new Image(die);
|
||||
}
|
||||
|
@@ -18,15 +18,15 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
private readonly IImagesService _images;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
private readonly NadekoRandom rng = new NadekoRandom();
|
||||
|
||||
public FlipCoinCommands(IImagesService images, CurrencyHandler ch, BotConfig bc)
|
||||
public FlipCoinCommands(IImagesService images, CurrencyService cs, BotConfig bc)
|
||||
{
|
||||
_images = images;
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@@ -74,47 +74,49 @@ namespace NadekoBot.Modules.Gambling
|
||||
await Context.Channel.SendFileAsync(imgs.Merge().ToStream(), $"{count} coins.png").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task Betflip(int amount, string guess)
|
||||
public enum BetFlipGuess
|
||||
{
|
||||
var guessStr = guess.Trim().ToUpperInvariant();
|
||||
if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS")
|
||||
return;
|
||||
H = 1,
|
||||
Head = 1,
|
||||
Heads = 1,
|
||||
T = 2,
|
||||
Tail = 2,
|
||||
Tails = 2
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task Betflip(int amount, BetFlipGuess guess)
|
||||
{
|
||||
if (amount < _bc.MinimumBetAmount)
|
||||
{
|
||||
await ReplyErrorLocalized("min_bet_limit", _bc.MinimumBetAmount + _bc.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var removed = await _ch.RemoveCurrencyAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false);
|
||||
var removed = await _cs.RemoveAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false);
|
||||
if (!removed)
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", _bc.CurrencyPluralName).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
//heads = true
|
||||
//tails = false
|
||||
|
||||
//todo this seems stinky, no time to look at it right now
|
||||
var isHeads = guessStr == "HEADS" || guessStr == "H";
|
||||
var result = false;
|
||||
BetFlipGuess result;
|
||||
IEnumerable<byte> imageToSend;
|
||||
if (rng.Next(0, 2) == 1)
|
||||
{
|
||||
imageToSend = _images.Heads;
|
||||
result = true;
|
||||
result = BetFlipGuess.Heads;
|
||||
}
|
||||
else
|
||||
{
|
||||
imageToSend = _images.Tails;
|
||||
result = BetFlipGuess.Tails;
|
||||
}
|
||||
|
||||
string str;
|
||||
if (isHeads == result)
|
||||
if (guess == result)
|
||||
{
|
||||
var toWin = (int)Math.Round(amount * _bc.BetflipMultiplier);
|
||||
str = Context.User.Mention + " " + GetText("flip_guess", toWin + _bc.CurrencySign);
|
||||
await _ch.AddCurrencyAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false);
|
||||
await _cs.AddAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -20,8 +20,8 @@ namespace NadekoBot.Modules.Gambling
|
||||
public class FlowerShop : NadekoSubmodule
|
||||
{
|
||||
private readonly BotConfig _bc;
|
||||
private readonly DbHandler _db;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly DbService _db;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DiscordShardedClient _client;
|
||||
|
||||
public enum Role
|
||||
@@ -34,11 +34,11 @@ namespace NadekoBot.Modules.Gambling
|
||||
List
|
||||
}
|
||||
|
||||
public FlowerShop(BotConfig bc, DbHandler db, CurrencyHandler ch, DiscordShardedClient client)
|
||||
public FlowerShop(BotConfig bc, DbService db, CurrencyService cs, DiscordShardedClient client)
|
||||
{
|
||||
_db = db;
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
return;
|
||||
}
|
||||
|
||||
if (await _ch.RemoveCurrencyAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
|
||||
if (await _cs.RemoveAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -120,11 +120,11 @@ namespace NadekoBot.Modules.Gambling
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warn(ex);
|
||||
await _ch.AddCurrencyAsync(Context.User.Id, $"Shop error refund", entry.Price);
|
||||
await _cs.AddAsync(Context.User.Id, $"Shop error refund", entry.Price);
|
||||
await ReplyErrorLocalized("shop_role_purchase_error").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
await _ch.AddCurrencyAsync(entry.AuthorId, $"Shop sell item - {entry.Type}", GetProfitAmount(entry.Price));
|
||||
await _cs.AddAsync(entry.AuthorId, $"Shop sell item - {entry.Type}", GetProfitAmount(entry.Price));
|
||||
await ReplyConfirmLocalized("shop_role_purchase", Format.Bold(role.Name)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
var item = entry.Items.ToArray()[new NadekoRandom().Next(0, entry.Items.Count)];
|
||||
|
||||
if (await _ch.RemoveCurrencyAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
|
||||
if (await _cs.RemoveAsync(Context.User.Id, $"Shop purchase - {entry.Type}", entry.Price))
|
||||
{
|
||||
int removed;
|
||||
using (var uow = _db.UnitOfWork)
|
||||
@@ -163,7 +163,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
.AddField(efb => efb.WithName(GetText("name")).WithValue(entry.Name).WithIsInline(true)))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await _ch.AddCurrencyAsync(entry.AuthorId,
|
||||
await _cs.AddAsync(entry.AuthorId,
|
||||
$"Shop sell item - {entry.Name}",
|
||||
GetProfitAmount(entry.Price)).ConfigureAwait(false);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
uow._context.Set<ShopEntryItem>().Add(item);
|
||||
uow.Complete();
|
||||
|
||||
await _ch.AddCurrencyAsync(Context.User.Id,
|
||||
await _cs.AddAsync(Context.User.Id,
|
||||
$"Shop error refund - {entry.Name}",
|
||||
entry.Price,
|
||||
uow).ConfigureAwait(false);
|
||||
|
@@ -32,13 +32,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
//thanks to judge for helping me with this
|
||||
|
||||
private readonly IImagesService _images;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
public Slots(IImagesService images, BotConfig bc, CurrencyHandler ch)
|
||||
public Slots(IImagesService images, BotConfig bc, CurrencyService cs)
|
||||
{
|
||||
_images = images;
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
}
|
||||
|
||||
public class SlotMachine
|
||||
@@ -157,7 +157,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await _ch.RemoveCurrencyAsync(Context.User, "Slot Machine", amount, false))
|
||||
if (!await _cs.RemoveAsync(Context.User, "Slot Machine", amount, false))
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
@@ -209,7 +209,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
var msg = GetText("better_luck");
|
||||
if (result.Multiplier != 0)
|
||||
{
|
||||
await _ch.AddCurrencyAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount * result.Multiplier, false);
|
||||
await _cs.AddAsync(Context.User, $"Slot Machine x{result.Multiplier}", amount * result.Multiplier, false);
|
||||
Interlocked.Add(ref _totalPaidOut, amount * result.Multiplier);
|
||||
if (result.Multiplier == 1)
|
||||
msg = GetText("slot_single", _bc.CurrencySign, 1);
|
||||
|
@@ -57,10 +57,10 @@ namespace NadekoBot.Modules.Gambling
|
||||
InsufficientAmount
|
||||
}
|
||||
|
||||
public WaifuClaimCommands(BotConfig bc, CurrencyHandler ch, DbHandler db)
|
||||
public WaifuClaimCommands(BotConfig bc, CurrencyService cs, DbService db)
|
||||
{
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
_db = db;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
var claimer = uow.DiscordUsers.GetOrCreate(Context.User);
|
||||
var waifu = uow.DiscordUsers.GetOrCreate(target);
|
||||
if (!await _ch.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
|
||||
{
|
||||
result = WaifuClaimResult.NotEnoughFunds;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
}
|
||||
else if (isAffinity && amount > w.Price * 0.88f)
|
||||
{
|
||||
if (!await _ch.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
|
||||
{
|
||||
result = WaifuClaimResult.NotEnoughFunds;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
}
|
||||
else if (amount >= w.Price * 1.1f) // if no affinity
|
||||
{
|
||||
if (!await _ch.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
|
||||
{
|
||||
result = WaifuClaimResult.NotEnoughFunds;
|
||||
}
|
||||
@@ -230,13 +230,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
if (w.Affinity?.UserId == Context.User.Id)
|
||||
{
|
||||
await _ch.AddCurrencyAsync(w.Waifu.UserId, "Waifu Compensation", amount, uow).ConfigureAwait(false);
|
||||
await _cs.AddAsync(w.Waifu.UserId, "Waifu Compensation", amount, uow).ConfigureAwait(false);
|
||||
w.Price = (int)Math.Floor(w.Price * 0.75f);
|
||||
result = DivorceResult.SucessWithPenalty;
|
||||
}
|
||||
else
|
||||
{
|
||||
await _ch.AddCurrencyAsync(Context.User.Id, "Waifu Refund", amount, uow).ConfigureAwait(false);
|
||||
await _cs.AddAsync(Context.User.Id, "Waifu Refund", amount, uow).ConfigureAwait(false);
|
||||
|
||||
result = DivorceResult.Success;
|
||||
}
|
||||
@@ -278,8 +278,8 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
private static readonly TimeSpan _affinityLimit = TimeSpan.FromMinutes(30);
|
||||
private readonly BotConfig _bc;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly DbHandler _db;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DbService _db;
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
@@ -13,14 +13,14 @@ namespace NadekoBot.Modules.Gambling
|
||||
public partial class Gambling : NadekoTopLevelModule
|
||||
{
|
||||
private readonly BotConfig _bc;
|
||||
private readonly DbHandler _db;
|
||||
private readonly CurrencyHandler _currency;
|
||||
private readonly DbService _db;
|
||||
private readonly CurrencyService _currency;
|
||||
|
||||
private string CurrencyName => _bc.CurrencyName;
|
||||
private string CurrencyPluralName => _bc.CurrencyPluralName;
|
||||
private string CurrencySign => _bc.CurrencySign;
|
||||
|
||||
public Gambling(BotConfig bc, DbHandler db, CurrencyHandler currency)
|
||||
public Gambling(BotConfig bc, DbService db, CurrencyService currency)
|
||||
{
|
||||
_bc = bc;
|
||||
_db = db;
|
||||
@@ -71,13 +71,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
if (amount <= 0 || Context.User.Id == receiver.Id)
|
||||
return;
|
||||
var success = await _currency.RemoveCurrencyAsync((IGuildUser)Context.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, false).ConfigureAwait(false);
|
||||
var success = await _currency.RemoveAsync((IGuildUser)Context.User, $"Gift to {receiver.Username} ({receiver.Id}).", amount, false).ConfigureAwait(false);
|
||||
if (!success)
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", CurrencyPluralName).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
await _currency.AddCurrencyAsync(receiver, $"Gift from {Context.User.Username} ({Context.User.Id}).", amount, true).ConfigureAwait(false);
|
||||
await _currency.AddAsync(receiver, $"Gift from {Context.User.Username} ({Context.User.Id}).", amount, true).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("gifted", amount + CurrencySign, Format.Bold(receiver.ToString()))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
@@ -97,7 +97,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
if (amount <= 0)
|
||||
return;
|
||||
|
||||
await _currency.AddCurrencyAsync(usrId, $"Awarded by bot owner. ({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false);
|
||||
await _currency.AddAsync(usrId, $"Awarded by bot owner. ({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("awarded", amount + CurrencySign, $"<@{usrId}>").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
var users = (await Context.Guild.GetUsersAsync())
|
||||
.Where(u => u.GetRoles().Contains(role))
|
||||
.ToList();
|
||||
await Task.WhenAll(users.Select(u => _currency.AddCurrencyAsync(u.Id,
|
||||
await Task.WhenAll(users.Select(u => _currency.AddAsync(u.Id,
|
||||
$"Awarded by bot owner to **{role.Name}** role. ({Context.User.Username}/{Context.User.Id})",
|
||||
amount)))
|
||||
.ConfigureAwait(false);
|
||||
@@ -129,7 +129,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
if (amount <= 0)
|
||||
return;
|
||||
|
||||
if (await _currency.RemoveCurrencyAsync(user, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount, true).ConfigureAwait(false))
|
||||
if (await _currency.RemoveAsync(user, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount, true).ConfigureAwait(false))
|
||||
await ReplyConfirmLocalized("take", amount+CurrencySign, Format.Bold(user.ToString())).ConfigureAwait(false);
|
||||
else
|
||||
await ReplyErrorLocalized("take_fail", amount + CurrencySign, Format.Bold(user.ToString()), CurrencyPluralName).ConfigureAwait(false);
|
||||
@@ -143,7 +143,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
if (amount <= 0)
|
||||
return;
|
||||
|
||||
if (await _currency.RemoveCurrencyAsync(usrId, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false))
|
||||
if (await _currency.RemoveAsync(usrId, $"Taken by bot owner.({Context.User.Username}/{Context.User.Id})", amount).ConfigureAwait(false))
|
||||
await ReplyConfirmLocalized("take", amount + CurrencySign, $"<@{usrId}>").ConfigureAwait(false);
|
||||
else
|
||||
await ReplyErrorLocalized("take_fail", amount + CurrencySign, Format.Code(usrId.ToString()), CurrencyPluralName).ConfigureAwait(false);
|
||||
@@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
if (amount < 1)
|
||||
return;
|
||||
|
||||
if (!await _currency.RemoveCurrencyAsync(Context.User, "Betroll Gamble", amount, false).ConfigureAwait(false))
|
||||
if (!await _currency.RemoveAsync(Context.User, "Betroll Gamble", amount, false).ConfigureAwait(false))
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", CurrencyPluralName).ConfigureAwait(false);
|
||||
return;
|
||||
@@ -227,19 +227,19 @@ namespace NadekoBot.Modules.Gambling
|
||||
if (rnd < 91)
|
||||
{
|
||||
str += GetText("br_win", (amount * _bc.Betroll67Multiplier) + CurrencySign, 66);
|
||||
await _currency.AddCurrencyAsync(Context.User, "Betroll Gamble",
|
||||
await _currency.AddAsync(Context.User, "Betroll Gamble",
|
||||
(int) (amount * _bc.Betroll67Multiplier), false).ConfigureAwait(false);
|
||||
}
|
||||
else if (rnd < 100)
|
||||
{
|
||||
str += GetText("br_win", (amount * _bc.Betroll91Multiplier) + CurrencySign, 90);
|
||||
await _currency.AddCurrencyAsync(Context.User, "Betroll Gamble",
|
||||
await _currency.AddAsync(Context.User, "Betroll Gamble",
|
||||
(int) (amount * _bc.Betroll91Multiplier), false).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
str += GetText("br_win", (amount * _bc.Betroll100Multiplier) + CurrencySign, 100) + " 👑";
|
||||
await _currency.AddCurrencyAsync(Context.User, "Betroll Gamble",
|
||||
await _currency.AddAsync(Context.User, "Betroll Gamble",
|
||||
(int) (amount * _bc.Betroll100Multiplier), false).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Games
|
||||
Voting
|
||||
}
|
||||
|
||||
//todo Isolate, this shouldn't print or anything like that.
|
||||
//todo 85 Isolate, this shouldn't print or anything like that.
|
||||
public class AcrophobiaGame
|
||||
{
|
||||
private readonly ITextChannel _channel;
|
||||
|
@@ -13,10 +13,10 @@ namespace NadekoBot.Modules.Games
|
||||
[Group]
|
||||
public class CleverBotCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly GamesService _games;
|
||||
private readonly DbService _db;
|
||||
private readonly ChatterBotService _games;
|
||||
|
||||
public CleverBotCommands(DbHandler db, GamesService games)
|
||||
public CleverBotCommands(DbService db, ChatterBotService games)
|
||||
{
|
||||
_db = db;
|
||||
_games = games;
|
||||
@@ -29,7 +29,7 @@ namespace NadekoBot.Modules.Games
|
||||
{
|
||||
var channel = (ITextChannel)Context.Channel;
|
||||
|
||||
if (_games.CleverbotGuilds.TryRemove(channel.Guild.Id, out Lazy<ChatterBotSession> throwaway))
|
||||
if (_games.ChatterBotGuilds.TryRemove(channel.Guild.Id, out Lazy<ChatterBotSession> throwaway))
|
||||
{
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
@@ -40,7 +40,7 @@ namespace NadekoBot.Modules.Games
|
||||
return;
|
||||
}
|
||||
|
||||
_games.CleverbotGuilds.TryAdd(channel.Guild.Id, new Lazy<ChatterBotSession>(() => new ChatterBotSession(Context.Guild.Id), true));
|
||||
_games.ChatterBotGuilds.TryAdd(channel.Guild.Id, new Lazy<ChatterBotSession>(() => new ChatterBotSession(Context.Guild.Id), true));
|
||||
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
|
@@ -24,16 +24,16 @@ namespace NadekoBot.Modules.Games
|
||||
[Group]
|
||||
public class PlantPickCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly GamesService _games;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public PlantPickCommands(BotConfig bc, CurrencyHandler ch, GamesService games,
|
||||
DbHandler db)
|
||||
public PlantPickCommands(BotConfig bc, CurrencyService cs, GamesService games,
|
||||
DbService db)
|
||||
{
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
_games = games;
|
||||
_db = db;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ namespace NadekoBot.Modules.Games
|
||||
|
||||
await Task.WhenAll(msgs.Where(m => m != null).Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);
|
||||
|
||||
await _ch.AddCurrencyAsync((IGuildUser)Context.User, $"Picked {_bc.CurrencyPluralName}", msgs.Count, false).ConfigureAwait(false);
|
||||
await _cs.AddAsync((IGuildUser)Context.User, $"Picked {_bc.CurrencyPluralName}", msgs.Count, false).ConfigureAwait(false);
|
||||
var msg = await ReplyConfirmLocalized("picked", msgs.Count + _bc.CurrencySign)
|
||||
.ConfigureAwait(false);
|
||||
msg.DeleteAfter(10);
|
||||
@@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Games
|
||||
if (amount < 1)
|
||||
return;
|
||||
|
||||
var removed = await _ch.RemoveCurrencyAsync((IGuildUser)Context.User, $"Planted a {_bc.CurrencyName}", amount, false).ConfigureAwait(false);
|
||||
var removed = await _cs.RemoveAsync((IGuildUser)Context.User, $"Planted a {_bc.CurrencyName}", amount, false).ConfigureAwait(false);
|
||||
if (!removed)
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
|
||||
@@ -88,9 +88,9 @@ namespace NadekoBot.Modules.Games
|
||||
msgToSend += " " + GetText("pick_sn", Prefix);
|
||||
|
||||
IUserMessage msg;
|
||||
using (var toSend = imgData.Value.ToStream())
|
||||
using (var toSend = imgData.Data.ToStream())
|
||||
{
|
||||
msg = await Context.Channel.SendFileAsync(toSend, imgData.Key, msgToSend).ConfigureAwait(false);
|
||||
msg = await Context.Channel.SendFileAsync(toSend, imgData.Name, msgToSend).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var msgs = new IUserMessage[amount];
|
||||
|
@@ -3,12 +3,8 @@ using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Games;
|
||||
|
||||
namespace NadekoBot.Modules.Games
|
||||
{
|
||||
@@ -17,12 +13,13 @@ namespace NadekoBot.Modules.Games
|
||||
[Group]
|
||||
public class PollCommands : NadekoSubmodule
|
||||
{
|
||||
public static ConcurrentDictionary<ulong, Poll> ActivePolls = new ConcurrentDictionary<ulong, Poll>();
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly PollService _polls;
|
||||
|
||||
public PollCommands(DiscordShardedClient client)
|
||||
public PollCommands(DiscordShardedClient client, PollService polls)
|
||||
{
|
||||
_client = client;
|
||||
_polls = polls;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@@ -42,8 +39,7 @@ namespace NadekoBot.Modules.Games
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task PollStats()
|
||||
{
|
||||
Poll poll;
|
||||
if (!ActivePolls.TryGetValue(Context.Guild.Id, out poll))
|
||||
if (!_polls.ActivePolls.TryGetValue(Context.Guild.Id, out var poll))
|
||||
return;
|
||||
|
||||
await Context.Channel.EmbedAsync(poll.GetStats(GetText("current_poll_results")));
|
||||
@@ -51,20 +47,7 @@ namespace NadekoBot.Modules.Games
|
||||
|
||||
private async Task InternalStartPoll(string arg, bool isPublic = false)
|
||||
{
|
||||
var channel = (ITextChannel)Context.Channel;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(arg) || !arg.Contains(";"))
|
||||
return;
|
||||
var data = arg.Split(';');
|
||||
if (data.Length < 3)
|
||||
return;
|
||||
|
||||
var poll = new Poll(_client, _strings, Context.Message, data[0], data.Skip(1), isPublic: isPublic);
|
||||
if (ActivePolls.TryAdd(channel.Guild.Id, poll))
|
||||
{
|
||||
await poll.StartPoll().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
if(await _polls.StartPoll((ITextChannel)Context.Channel, Context.Message, arg, isPublic) == false)
|
||||
await ReplyErrorLocalized("poll_already_running").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -75,151 +58,11 @@ namespace NadekoBot.Modules.Games
|
||||
{
|
||||
var channel = (ITextChannel)Context.Channel;
|
||||
|
||||
Poll poll;
|
||||
ActivePolls.TryRemove(channel.Guild.Id, out poll);
|
||||
_polls.ActivePolls.TryRemove(channel.Guild.Id, out var poll);
|
||||
await poll.StopPoll().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public class Poll
|
||||
{
|
||||
private readonly IUserMessage _originalMessage;
|
||||
private readonly IGuild _guild;
|
||||
private string[] answers { get; }
|
||||
private readonly ConcurrentDictionary<ulong, int> _participants = new ConcurrentDictionary<ulong, int>();
|
||||
private readonly string _question;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly NadekoStrings _strings;
|
||||
|
||||
public bool IsPublic { get; }
|
||||
|
||||
public Poll(DiscordShardedClient client, NadekoStrings strings, IUserMessage umsg, string question, IEnumerable<string> enumerable, bool isPublic = false)
|
||||
{
|
||||
_client = client;
|
||||
_strings = strings;
|
||||
|
||||
_originalMessage = umsg;
|
||||
_guild = ((ITextChannel)umsg.Channel).Guild;
|
||||
_question = question;
|
||||
answers = enumerable as string[] ?? enumerable.ToArray();
|
||||
IsPublic = isPublic;
|
||||
}
|
||||
|
||||
public EmbedBuilder GetStats(string title)
|
||||
{
|
||||
var results = _participants.GroupBy(kvp => kvp.Value)
|
||||
.ToDictionary(x => x.Key, x => x.Sum(kvp => 1))
|
||||
.OrderByDescending(kvp => kvp.Value)
|
||||
.ToArray();
|
||||
|
||||
var eb = new EmbedBuilder().WithTitle(title);
|
||||
|
||||
var sb = new StringBuilder()
|
||||
.AppendLine(Format.Bold(_question))
|
||||
.AppendLine();
|
||||
|
||||
var totalVotesCast = 0;
|
||||
if (results.Length == 0)
|
||||
{
|
||||
sb.AppendLine(GetText("no_votes_cast"));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < results.Length; i++)
|
||||
{
|
||||
var result = results[i];
|
||||
sb.AppendLine(GetText("poll_result",
|
||||
result.Key,
|
||||
Format.Bold(answers[result.Key - 1]),
|
||||
Format.Bold(result.Value.ToString())));
|
||||
totalVotesCast += result.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
eb.WithDescription(sb.ToString())
|
||||
.WithFooter(efb => efb.WithText(GetText("x_votes_cast", totalVotesCast)));
|
||||
|
||||
return eb;
|
||||
}
|
||||
|
||||
public async Task StartPoll()
|
||||
{
|
||||
_client.MessageReceived += Vote;
|
||||
var msgToSend = GetText("poll_created", Format.Bold(_originalMessage.Author.Username)) + "\n\n" + Format.Bold(_question) + "\n";
|
||||
var num = 1;
|
||||
msgToSend = answers.Aggregate(msgToSend, (current, answ) => current + $"`{num++}.` **{answ}**\n");
|
||||
if (!IsPublic)
|
||||
msgToSend += "\n" + Format.Bold(GetText("poll_vote_private"));
|
||||
else
|
||||
msgToSend += "\n" + Format.Bold(GetText("poll_vote_public"));
|
||||
await _originalMessage.Channel.SendConfirmAsync(msgToSend).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task StopPoll()
|
||||
{
|
||||
_client.MessageReceived -= Vote;
|
||||
await _originalMessage.Channel.EmbedAsync(GetStats("POLL CLOSED")).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task Vote(SocketMessage imsg)
|
||||
{
|
||||
try
|
||||
{
|
||||
// has to be a user message
|
||||
var msg = imsg as SocketUserMessage;
|
||||
if (msg == null || msg.Author.IsBot)
|
||||
return;
|
||||
|
||||
// has to be an integer
|
||||
int vote;
|
||||
if (!int.TryParse(imsg.Content, out vote))
|
||||
return;
|
||||
if (vote < 1 || vote > answers.Length)
|
||||
return;
|
||||
|
||||
IMessageChannel ch;
|
||||
if (IsPublic)
|
||||
{
|
||||
//if public, channel must be the same the poll started in
|
||||
if (_originalMessage.Channel.Id != imsg.Channel.Id)
|
||||
return;
|
||||
ch = imsg.Channel;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if private, channel must be dm channel
|
||||
if ((ch = msg.Channel as IDMChannel) == null)
|
||||
return;
|
||||
|
||||
// user must be a member of the guild this poll is in
|
||||
var guildUsers = await _guild.GetUsersAsync().ConfigureAwait(false);
|
||||
if (guildUsers.All(u => u.Id != imsg.Author.Id))
|
||||
return;
|
||||
}
|
||||
|
||||
//user can vote only once
|
||||
if (_participants.TryAdd(msg.Author.Id, vote))
|
||||
{
|
||||
if (!IsPublic)
|
||||
{
|
||||
await ch.SendConfirmAsync(GetText("thanks_for_voting", Format.Bold(msg.Author.Username))).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var toDelete = await ch.SendConfirmAsync(GetText("poll_voted", Format.Bold(msg.Author.ToString()))).ConfigureAwait(false);
|
||||
toDelete.DeleteAfter(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private string GetText(string key, params object[] replacements)
|
||||
=> _strings.GetText(key,
|
||||
_guild.Id,
|
||||
typeof(Games).Name.ToLowerInvariant(),
|
||||
replacements);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -6,7 +6,6 @@ using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Games.Models;
|
||||
using NadekoBot.Services.Games;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -71,15 +70,10 @@ namespace NadekoBot.Modules.Games
|
||||
public async Task Typeadd([Remainder] string text)
|
||||
{
|
||||
var channel = (ITextChannel)Context.Channel;
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
return;
|
||||
|
||||
_games.TypingArticles.Add(new TypingArticle
|
||||
{
|
||||
Title = $"Text added on {DateTime.UtcNow} by {Context.User}",
|
||||
Text = text.SanitizeMentions(),
|
||||
});
|
||||
|
||||
//todo move this to service
|
||||
File.WriteAllText(_games.TypingArticlesPath, JsonConvert.SerializeObject(_games.TypingArticles));
|
||||
_games.AddTypingArticle(Context.User, text);
|
||||
|
||||
await channel.SendConfirmAsync("Added new article for typing game.").ConfigureAwait(false);
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ namespace NadekoBot.Modules.Games.Trivia
|
||||
private readonly NadekoStrings _strings;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
public IGuild Guild { get; }
|
||||
public ITextChannel Channel { get; }
|
||||
@@ -44,14 +44,14 @@ namespace NadekoBot.Modules.Games.Trivia
|
||||
public int WinRequirement { get; }
|
||||
|
||||
public TriviaGame(NadekoStrings strings, DiscordShardedClient client, BotConfig bc,
|
||||
CurrencyHandler ch, IGuild guild, ITextChannel channel,
|
||||
CurrencyService cs, IGuild guild, ITextChannel channel,
|
||||
bool showHints, int winReq, bool isPokemon)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_strings = strings;
|
||||
_client = client;
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
|
||||
ShowHints = showHints;
|
||||
Guild = guild;
|
||||
@@ -227,7 +227,7 @@ namespace NadekoBot.Modules.Games.Trivia
|
||||
}
|
||||
var reward = _bc.TriviaCurrencyReward;
|
||||
if (reward > 0)
|
||||
await _ch.AddCurrencyAsync(guildUser, "Won trivia", reward, true).ConfigureAwait(false);
|
||||
await _cs.AddAsync(guildUser, "Won trivia", reward, true).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -17,15 +17,15 @@ namespace NadekoBot.Modules.Games
|
||||
[Group]
|
||||
public class TriviaCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly BotConfig _bc;
|
||||
|
||||
public static ConcurrentDictionary<ulong, TriviaGame> RunningTrivias { get; } = new ConcurrentDictionary<ulong, TriviaGame>();
|
||||
|
||||
public TriviaCommands(DiscordShardedClient client, BotConfig bc, CurrencyHandler ch)
|
||||
public TriviaCommands(DiscordShardedClient client, BotConfig bc, CurrencyService cs)
|
||||
{
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
_client = client;
|
||||
_bc = bc;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Games
|
||||
var showHints = !additionalArgs.Contains("nohint");
|
||||
var isPokemon = additionalArgs.Contains("pokemon");
|
||||
|
||||
var trivia = new TriviaGame(_strings, _client, _bc, _ch, channel.Guild, channel, showHints, winReq, isPokemon);
|
||||
var trivia = new TriviaGame(_strings, _client, _bc, _cs, channel.Guild, channel, showHints, winReq, isPokemon);
|
||||
if (RunningTrivias.TryAdd(channel.Guild.Id, trivia))
|
||||
{
|
||||
try
|
||||
|
@@ -14,19 +14,21 @@ using System.Collections.Generic;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Threading;
|
||||
using NadekoBot.Services.Music;
|
||||
using NadekoBot.DataStructures;
|
||||
|
||||
namespace NadekoBot.Modules.Music
|
||||
{
|
||||
[NoPublicBot]
|
||||
public class Music : NadekoTopLevelModule
|
||||
{
|
||||
private static MusicService _music;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly IBotCredentials _creds;
|
||||
private readonly IGoogleApiService _google;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public Music(DiscordShardedClient client, IBotCredentials creds, IGoogleApiService google,
|
||||
DbHandler db, MusicService music)
|
||||
DbService db, MusicService music)
|
||||
{
|
||||
_client = client;
|
||||
_creds = creds;
|
||||
|
@@ -23,14 +23,14 @@ namespace NadekoBot.Modules.Permissions
|
||||
public class BlacklistCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly BlacklistService _bs;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly IBotCredentials _creds;
|
||||
|
||||
private ConcurrentHashSet<ulong> BlacklistedUsers => _bs.BlacklistedUsers;
|
||||
private ConcurrentHashSet<ulong> BlacklistedGuilds => _bs.BlacklistedGuilds;
|
||||
private ConcurrentHashSet<ulong> BlacklistedChannels => _bs.BlacklistedChannels;
|
||||
|
||||
public BlacklistCommands(BlacklistService bs, DbHandler db, IBotCredentials creds)
|
||||
public BlacklistCommands(BlacklistService bs, DbService db, IBotCredentials creds)
|
||||
{
|
||||
_bs = bs;
|
||||
_db = db;
|
||||
|
@@ -17,7 +17,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
[Group]
|
||||
public class CmdCdsCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly CmdCdService _service;
|
||||
|
||||
private ConcurrentDictionary<ulong, ConcurrentHashSet<CommandCooldown>> CommandCooldowns
|
||||
@@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
private ConcurrentDictionary<ulong, ConcurrentHashSet<ActiveCooldown>> ActiveCooldowns
|
||||
=> _service.ActiveCooldowns;
|
||||
|
||||
public CmdCdsCommands(CmdCdService service, DbHandler db)
|
||||
public CmdCdsCommands(CmdCdService service, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
@@ -88,40 +88,6 @@ namespace NadekoBot.Modules.Permissions
|
||||
else
|
||||
await channel.SendTableAsync("", localSet.Select(c => c.CommandName + ": " + c.Seconds + GetText("sec")), s => $"{s,-30}", 2).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public bool HasCooldown(CommandInfo cmd, IGuild guild, IUser user)
|
||||
{
|
||||
if (guild == null)
|
||||
return false;
|
||||
var cmdcds = CommandCooldowns.GetOrAdd(guild.Id, new ConcurrentHashSet<CommandCooldown>());
|
||||
CommandCooldown cdRule;
|
||||
if ((cdRule = cmdcds.FirstOrDefault(cc => cc.CommandName == cmd.Aliases.First().ToLowerInvariant())) != null)
|
||||
{
|
||||
var activeCdsForGuild = ActiveCooldowns.GetOrAdd(guild.Id, new ConcurrentHashSet<ActiveCooldown>());
|
||||
if (activeCdsForGuild.FirstOrDefault(ac => ac.UserId == user.Id && ac.Command == cmd.Aliases.First().ToLowerInvariant()) != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
activeCdsForGuild.Add(new ActiveCooldown()
|
||||
{
|
||||
UserId = user.Id,
|
||||
Command = cmd.Aliases.First().ToLowerInvariant(),
|
||||
});
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(cdRule.Seconds * 1000);
|
||||
activeCdsForGuild.RemoveWhere(ac => ac.Command == cmd.Aliases.First().ToLowerInvariant() && ac.UserId == user.Id);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,10 +15,10 @@ namespace NadekoBot.Modules.Permissions
|
||||
[Group]
|
||||
public class FilterCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly FilterService _service;
|
||||
|
||||
public FilterCommands(FilterService service, DbHandler db)
|
||||
public FilterCommands(FilterService service, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
|
@@ -16,9 +16,9 @@ namespace NadekoBot.Modules.Permissions
|
||||
public class GlobalPermissionCommands : NadekoSubmodule
|
||||
{
|
||||
private GlobalPermissionService _service;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public GlobalPermissionCommands(GlobalPermissionService service, DbHandler db)
|
||||
public GlobalPermissionCommands(GlobalPermissionService service, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
|
@@ -14,10 +14,10 @@ namespace NadekoBot.Modules.Permissions.Commands
|
||||
public class ResetPermissionsCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly PermissionsService _service;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly GlobalPermissionService _globalPerms;
|
||||
|
||||
public ResetPermissionsCommands(PermissionsService service, GlobalPermissionService globalPerms, DbHandler db)
|
||||
public ResetPermissionsCommands(PermissionsService service, GlobalPermissionService globalPerms, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
@@ -29,7 +29,7 @@ namespace NadekoBot.Modules.Permissions.Commands
|
||||
[RequireUserPermission(GuildPermission.Administrator)]
|
||||
public async Task ResetPermissions()
|
||||
{
|
||||
//todo 80 move to service
|
||||
//todo 50 move to service
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
var config = uow.GuildConfigs.GcWithPermissionsv2For(Context.Guild.Id);
|
||||
@@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Permissions.Commands
|
||||
[OwnerOnly]
|
||||
public async Task ResetGlobalPermissions()
|
||||
{
|
||||
//todo 80 move to service
|
||||
//todo 50 move to service
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
var gc = uow.BotConfig.GetOrCreate();
|
||||
|
@@ -15,10 +15,10 @@ namespace NadekoBot.Modules.Permissions
|
||||
{
|
||||
public partial class Permissions : NadekoTopLevelModule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly PermissionsService _service;
|
||||
|
||||
public Permissions(PermissionsService service, DbHandler db)
|
||||
public Permissions(PermissionsService service, DbService db)
|
||||
{
|
||||
_db = db;
|
||||
_service = service;
|
||||
|
@@ -15,16 +15,16 @@ namespace NadekoBot.Modules.Pokemon
|
||||
public class Pokemon : NadekoTopLevelModule
|
||||
{
|
||||
private readonly PokemonService _service;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly CurrencyHandler _ch;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
public Pokemon(PokemonService pokemonService, DbHandler db, BotConfig bc, CurrencyHandler ch)
|
||||
public Pokemon(PokemonService pokemonService, DbService db, BotConfig bc, CurrencyService cs)
|
||||
{
|
||||
_service = pokemonService;
|
||||
_db = db;
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
_cs = cs;
|
||||
}
|
||||
|
||||
private int GetDamage(PokemonType usertype, PokemonType targetType)
|
||||
@@ -229,7 +229,7 @@ namespace NadekoBot.Modules.Pokemon
|
||||
var target = (targetUser.Id == user.Id) ? "yourself" : targetUser.Mention;
|
||||
if (amount > 0)
|
||||
{
|
||||
if (!await _ch.RemoveCurrencyAsync(user, $"Poke-Heal {target}", amount, true).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(user, $"Poke-Heal {target}", amount, true).ConfigureAwait(false))
|
||||
{
|
||||
await ReplyErrorLocalized("no_currency", _bc.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
@@ -295,7 +295,7 @@ namespace NadekoBot.Modules.Pokemon
|
||||
var amount = 1;
|
||||
if (amount > 0)
|
||||
{
|
||||
if (!await _ch.RemoveCurrencyAsync(user, $"{user} change type to {typeTargeted}", amount, true).ConfigureAwait(false))
|
||||
if (!await _cs.RemoveAsync(user, $"{user} change type to {typeTargeted}", amount, true).ConfigureAwait(false))
|
||||
{
|
||||
await ReplyErrorLocalized("no_currency", _bc.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
|
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
//todo drawing
|
||||
//todo 50 drawing
|
||||
namespace NadekoBot.Modules.Searches
|
||||
{
|
||||
public partial class Searches
|
||||
|
@@ -17,10 +17,10 @@ namespace NadekoBot.Modules.Searches
|
||||
[Group]
|
||||
public class StreamNotificationCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly StreamNotificationService _service;
|
||||
|
||||
public StreamNotificationCommands(DbHandler db, StreamNotificationService service)
|
||||
public StreamNotificationCommands(DbService db, StreamNotificationService service)
|
||||
{
|
||||
_db = db;
|
||||
_service = service;
|
||||
|
@@ -59,7 +59,7 @@ namespace NadekoBot.Modules.Searches
|
||||
return;
|
||||
}
|
||||
|
||||
if (_searches.TranslatedChannels.TryRemove(channel.Id, out var throwaway))
|
||||
if (_searches.TranslatedChannels.TryRemove(channel.Id, out _))
|
||||
{
|
||||
await ReplyConfirmLocalized("atl_stopped").ConfigureAwait(false);
|
||||
return;
|
||||
|
@@ -20,10 +20,10 @@ namespace NadekoBot.Modules.Utility
|
||||
public class CommandMapCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly UtilityService _service;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
private readonly DiscordShardedClient _client;
|
||||
|
||||
public CommandMapCommands(UtilityService service, DbHandler db, DiscordShardedClient client)
|
||||
public CommandMapCommands(UtilityService service, DbService db, DiscordShardedClient client)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
|
@@ -18,13 +18,13 @@ namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly IStatsService _stats;
|
||||
private readonly CommandHandler _ch;
|
||||
private readonly CommandHandler _cmdHandler;
|
||||
|
||||
public InfoCommands(DiscordShardedClient client, IStatsService stats, CommandHandler ch)
|
||||
{
|
||||
_client = client;
|
||||
_stats = stats;
|
||||
_ch = ch;
|
||||
_cmdHandler = ch;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@@ -129,7 +129,7 @@ namespace NadekoBot.Modules.Utility
|
||||
int startCount = page * activityPerPage;
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
foreach (var kvp in _ch.UserMessagesSent.OrderByDescending(kvp => kvp.Value).Skip(page * activityPerPage).Take(activityPerPage))
|
||||
foreach (var kvp in _cmdHandler.UserMessagesSent.OrderByDescending(kvp => kvp.Value).Skip(page * activityPerPage).Take(activityPerPage))
|
||||
{
|
||||
str.AppendLine(GetText("activity_line",
|
||||
++startCount,
|
||||
@@ -141,7 +141,7 @@ namespace NadekoBot.Modules.Utility
|
||||
.WithTitle(GetText("activity_page", page + 1))
|
||||
.WithOkColor()
|
||||
.WithFooter(efb => efb.WithText(GetText("activity_users_total",
|
||||
_ch.UserMessagesSent.Count)))
|
||||
_cmdHandler.UserMessagesSent.Count)))
|
||||
.WithDescription(str.ToString()));
|
||||
}
|
||||
}
|
||||
|
@@ -22,9 +22,9 @@ namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
private readonly MessageRepeaterService _service;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public RepeatCommands(MessageRepeaterService service, DiscordShardedClient client, DbHandler db)
|
||||
public RepeatCommands(MessageRepeaterService service, DiscordShardedClient client, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_client = client;
|
||||
|
@@ -1,19 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Modules.Utility.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Extensions;
|
||||
using Discord;
|
||||
using NLog;
|
||||
using NadekoBot.Services.Utility;
|
||||
|
||||
namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
@@ -22,27 +15,26 @@ namespace NadekoBot.Modules.Utility
|
||||
[Group]
|
||||
public class PatreonCommands : NadekoSubmodule
|
||||
{
|
||||
//todo rename patreon thingy and move it to be a service, or a part of utility service
|
||||
private readonly PatreonThingy patreon;
|
||||
private readonly PatreonRewardsService _patreon;
|
||||
private readonly IBotCredentials _creds;
|
||||
private readonly BotConfig _config;
|
||||
private readonly DbHandler _db;
|
||||
private readonly CurrencyHandler _currency;
|
||||
private readonly DbService _db;
|
||||
private readonly CurrencyService _currency;
|
||||
|
||||
public PatreonCommands(IBotCredentials creds, BotConfig config, DbHandler db, CurrencyHandler currency)
|
||||
public PatreonCommands(PatreonRewardsService p, IBotCredentials creds, BotConfig config, DbService db, CurrencyService currency)
|
||||
{
|
||||
_creds = creds;
|
||||
_config = config;
|
||||
_db = db;
|
||||
_currency = currency;
|
||||
patreon = PatreonThingy.GetInstance(creds, db, currency);
|
||||
_patreon = p;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public async Task PatreonRewardsReload()
|
||||
{
|
||||
await patreon.LoadPledges().ConfigureAwait(false);
|
||||
await _patreon.LoadPledges().ConfigureAwait(false);
|
||||
|
||||
await Context.Channel.SendConfirmAsync("👌").ConfigureAwait(false);
|
||||
}
|
||||
@@ -60,7 +52,7 @@ namespace NadekoBot.Modules.Utility
|
||||
int amount = 0;
|
||||
try
|
||||
{
|
||||
amount = await patreon.ClaimReward(Context.User.Id).ConfigureAwait(false);
|
||||
amount = await _patreon.ClaimReward(Context.User.Id).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -72,7 +64,7 @@ namespace NadekoBot.Modules.Utility
|
||||
await ReplyConfirmLocalized("clpa_success", amount + _config.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var rem = (patreon.Interval - (DateTime.UtcNow - patreon.LastUpdate));
|
||||
var rem = (_patreon.Interval - (DateTime.UtcNow - _patreon.LastUpdate));
|
||||
var helpcmd = Format.Code(NadekoBot.Prefix + "donate");
|
||||
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
||||
.WithDescription(GetText("clpa_fail"))
|
||||
@@ -85,158 +77,5 @@ namespace NadekoBot.Modules.Utility
|
||||
}
|
||||
}
|
||||
|
||||
public class PatreonThingy
|
||||
{
|
||||
//todo quickly hacked while rewriting, fix this
|
||||
private static PatreonThingy _instance = null;
|
||||
public static PatreonThingy GetInstance(IBotCredentials creds, DbHandler db, CurrencyHandler cur)
|
||||
=> _instance ?? (_instance = new PatreonThingy(creds, db, cur));
|
||||
|
||||
private readonly SemaphoreSlim getPledgesLocker = new SemaphoreSlim(1, 1);
|
||||
|
||||
public ImmutableArray<PatreonUserAndReward> Pledges { get; private set; }
|
||||
public DateTime LastUpdate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public readonly Timer Updater;
|
||||
private readonly SemaphoreSlim claimLockJustInCase = new SemaphoreSlim(1, 1);
|
||||
private readonly Logger _log;
|
||||
|
||||
public readonly TimeSpan Interval = TimeSpan.FromHours(1);
|
||||
private IBotCredentials _creds;
|
||||
private readonly DbHandler _db;
|
||||
private readonly CurrencyHandler _currency;
|
||||
|
||||
static PatreonThingy() { }
|
||||
private PatreonThingy(IBotCredentials creds, DbHandler db, CurrencyHandler currency)
|
||||
{
|
||||
_creds = creds;
|
||||
_db = db;
|
||||
_currency = currency;
|
||||
if (string.IsNullOrWhiteSpace(creds.PatreonAccessToken))
|
||||
return;
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
Updater = new Timer(async (_) => await LoadPledges(), null, TimeSpan.Zero, Interval);
|
||||
}
|
||||
|
||||
public async Task LoadPledges()
|
||||
{
|
||||
LastUpdate = DateTime.UtcNow;
|
||||
await getPledgesLocker.WaitAsync(1000).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
var rewards = new List<PatreonPledge>();
|
||||
var users = new List<PatreonUser>();
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
http.DefaultRequestHeaders.Clear();
|
||||
http.DefaultRequestHeaders.Add("Authorization", "Bearer " + _creds.PatreonAccessToken);
|
||||
var data = new PatreonData()
|
||||
{
|
||||
Links = new PatreonDataLinks()
|
||||
{
|
||||
next = "https://api.patreon.com/oauth2/api/campaigns/334038/pledges"
|
||||
}
|
||||
};
|
||||
do
|
||||
{
|
||||
var res = await http.GetStringAsync(data.Links.next)
|
||||
.ConfigureAwait(false);
|
||||
data = JsonConvert.DeserializeObject<PatreonData>(res);
|
||||
var pledgers = data.Data.Where(x => x["type"].ToString() == "pledge");
|
||||
rewards.AddRange(pledgers.Select(x => JsonConvert.DeserializeObject<PatreonPledge>(x.ToString()))
|
||||
.Where(x => x.attributes.declined_since == null));
|
||||
users.AddRange(data.Included
|
||||
.Where(x => x["type"].ToString() == "user")
|
||||
.Select(x => JsonConvert.DeserializeObject<PatreonUser>(x.ToString())));
|
||||
} while (!string.IsNullOrWhiteSpace(data.Links.next));
|
||||
}
|
||||
Pledges = rewards.Join(users, (r) => r.relationships?.patron?.data?.id, (u) => u.id, (x, y) => new PatreonUserAndReward()
|
||||
{
|
||||
User = y,
|
||||
Reward = x,
|
||||
}).ToImmutableArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warn(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromMinutes(5)).ConfigureAwait(false);
|
||||
getPledgesLocker.Release();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> ClaimReward(ulong userId)
|
||||
{
|
||||
await claimLockJustInCase.WaitAsync();
|
||||
var now = DateTime.UtcNow;
|
||||
try
|
||||
{
|
||||
var data = Pledges.FirstOrDefault(x => x.User.attributes?.social_connections?.discord?.user_id == userId.ToString());
|
||||
|
||||
if (data == null)
|
||||
return 0;
|
||||
|
||||
var amount = data.Reward.attributes.amount_cents;
|
||||
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
var users = uow._context.Set<RewardedUser>();
|
||||
var usr = users.FirstOrDefault(x => x.PatreonUserId == data.User.id);
|
||||
|
||||
if (usr == null)
|
||||
{
|
||||
users.Add(new RewardedUser()
|
||||
{
|
||||
UserId = userId,
|
||||
PatreonUserId = data.User.id,
|
||||
LastReward = now,
|
||||
AmountRewardedThisMonth = amount,
|
||||
});
|
||||
|
||||
await _currency.AddCurrencyAsync(userId, "Patreon reward - new", amount, uow).ConfigureAwait(false);
|
||||
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
return amount;
|
||||
}
|
||||
|
||||
if (usr.LastReward.Month != now.Month)
|
||||
{
|
||||
usr.LastReward = now;
|
||||
usr.AmountRewardedThisMonth = amount;
|
||||
usr.PatreonUserId = data.User.id;
|
||||
|
||||
await _currency.AddCurrencyAsync(userId, "Patreon reward - recurring", amount, uow).ConfigureAwait(false);
|
||||
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
return amount;
|
||||
}
|
||||
|
||||
if ( usr.AmountRewardedThisMonth < amount)
|
||||
{
|
||||
var toAward = amount - usr.AmountRewardedThisMonth;
|
||||
|
||||
usr.LastReward = now;
|
||||
usr.AmountRewardedThisMonth = amount;
|
||||
usr.PatreonUserId = data.User.id;
|
||||
|
||||
await _currency.AddCurrencyAsync(usr.UserId, "Patreon reward - update", toAward, uow).ConfigureAwait(false);
|
||||
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
return toAward;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
finally
|
||||
{
|
||||
claimLockJustInCase.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,9 +17,9 @@ namespace NadekoBot.Modules.Utility
|
||||
[Group]
|
||||
public class QuoteCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public QuoteCommands(DbHandler db)
|
||||
public QuoteCommands(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
@@ -18,9 +18,9 @@ namespace NadekoBot.Modules.Utility
|
||||
public class RemindCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly RemindService _service;
|
||||
private readonly DbHandler _db;
|
||||
private readonly DbService _db;
|
||||
|
||||
public RemindCommands(RemindService service, DbHandler db)
|
||||
public RemindCommands(RemindService service, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
|
@@ -1,23 +0,0 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace NadekoBot.Modules.Utility.Models
|
||||
{
|
||||
public class PatreonData
|
||||
{
|
||||
public JObject[] Included { get; set; }
|
||||
public JObject[] Data { get; set; }
|
||||
public PatreonDataLinks Links { get; set; }
|
||||
}
|
||||
|
||||
public class PatreonDataLinks
|
||||
{
|
||||
public string first { get; set; }
|
||||
public string next { get; set; }
|
||||
}
|
||||
|
||||
public class PatreonUserAndReward
|
||||
{
|
||||
public PatreonUser User { get; set; }
|
||||
public PatreonPledge Reward { get; set; }
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
namespace NadekoBot.Modules.Utility.Models
|
||||
{
|
||||
public class Attributes
|
||||
{
|
||||
public int amount_cents { get; set; }
|
||||
public string created_at { get; set; }
|
||||
public object 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 Address
|
||||
{
|
||||
public object data { get; set; }
|
||||
}
|
||||
|
||||
public class Data
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
|
||||
public class Links
|
||||
{
|
||||
public string related { get; set; }
|
||||
}
|
||||
|
||||
public class Creator
|
||||
{
|
||||
public Data data { get; set; }
|
||||
public Links links { get; set; }
|
||||
}
|
||||
|
||||
public class Patron
|
||||
{
|
||||
public Data data { get; set; }
|
||||
public Links links { get; set; }
|
||||
}
|
||||
|
||||
public class Reward
|
||||
{
|
||||
public Data data { get; set; }
|
||||
public Links links { get; set; }
|
||||
}
|
||||
|
||||
public class Relationships
|
||||
{
|
||||
public Address address { get; set; }
|
||||
public Creator creator { get; set; }
|
||||
public Patron patron { get; set; }
|
||||
public Reward reward { get; set; }
|
||||
}
|
||||
|
||||
public class PatreonPledge
|
||||
{
|
||||
public Attributes attributes { get; set; }
|
||||
public string id { get; set; }
|
||||
public Relationships relationships { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
namespace NadekoBot.Modules.Utility.Models
|
||||
{
|
||||
public class DiscordConnection
|
||||
{
|
||||
public string user_id { get; set; }
|
||||
}
|
||||
|
||||
public class SocialConnections
|
||||
{
|
||||
public object deviantart { get; set; }
|
||||
public DiscordConnection discord { get; set; }
|
||||
public object facebook { get; set; }
|
||||
public object spotify { get; set; }
|
||||
public object twitch { get; set; }
|
||||
public object twitter { get; set; }
|
||||
public object youtube { get; set; }
|
||||
}
|
||||
|
||||
public class UserAttributes
|
||||
{
|
||||
public string about { get; set; }
|
||||
public string created { get; set; }
|
||||
public object discord_id { get; set; }
|
||||
public string email { get; set; }
|
||||
public object facebook { get; set; }
|
||||
public object facebook_id { get; set; }
|
||||
public string first_name { get; set; }
|
||||
public string full_name { get; set; }
|
||||
public int gender { get; set; }
|
||||
public bool has_password { get; set; }
|
||||
public string image_url { get; set; }
|
||||
public bool is_deleted { get; set; }
|
||||
public bool is_nuked { get; set; }
|
||||
public bool is_suspended { get; set; }
|
||||
public string last_name { get; set; }
|
||||
public SocialConnections social_connections { get; set; }
|
||||
public int status { get; set; }
|
||||
public string thumb_url { get; set; }
|
||||
public object twitch { get; set; }
|
||||
public string twitter { get; set; }
|
||||
public string url { get; set; }
|
||||
public string vanity { get; set; }
|
||||
public object youtube { get; set; }
|
||||
}
|
||||
|
||||
public class Campaign
|
||||
{
|
||||
public Data data { get; set; }
|
||||
public Links links { get; set; }
|
||||
}
|
||||
|
||||
public class UserRelationships
|
||||
{
|
||||
public Campaign campaign { get; set; }
|
||||
}
|
||||
|
||||
public class PatreonUser
|
||||
{
|
||||
public UserAttributes attributes { get; set; }
|
||||
public string id { get; set; }
|
||||
public UserRelationships relationships { get; set; }
|
||||
public string type { get; set; }
|
||||
}
|
||||
}
|
@@ -494,7 +494,6 @@ namespace NadekoBot.Services.Utility
|
||||
}
|
||||
else if (s.Embeds.Any())
|
||||
{
|
||||
//todo probably just go through all properties and check if they are set, if they are, add them
|
||||
msg += "EMBEDS: " + string.Join("\n--------\n", s.Embeds.Select(x => $"Description: {x.Description}"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user