2016-09-08 20:27:39 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2016-12-03 13:14:37 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2016-09-08 20:27:39 +00:00
|
|
|
|
using NadekoBot.Extensions;
|
|
|
|
|
using NadekoBot.Services;
|
2016-10-11 03:27:36 +00:00
|
|
|
|
using NadekoBot.Services.Database.Models;
|
2016-09-08 20:27:39 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Modules.Games.Services;
|
2016-09-08 20:27:39 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Games
|
|
|
|
|
{
|
|
|
|
|
public partial class Games
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Flower picking/planting idea is given to me by its
|
|
|
|
|
/// inceptor Violent Crumble from Game Developers League discord server
|
|
|
|
|
/// (he has !cookie and !nom) Thanks a lot Violent!
|
|
|
|
|
/// Check out GDL (its a growing gamedev community):
|
|
|
|
|
/// https://discord.gg/0TYNJfCU4De7YIk8
|
|
|
|
|
/// </summary>
|
2016-09-08 20:46:38 +00:00
|
|
|
|
[Group]
|
2017-10-04 22:51:12 +00:00
|
|
|
|
public class PlantPickCommands : NadekoSubmodule<GamesService>
|
2016-09-08 20:27:39 +00:00
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly CurrencyService _cs;
|
2017-07-20 03:10:39 +00:00
|
|
|
|
private readonly IBotConfigProvider _bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly DbService _db;
|
2016-09-08 20:27:39 +00:00
|
|
|
|
|
2017-10-04 22:51:12 +00:00
|
|
|
|
public PlantPickCommands(IBotConfigProvider bc, CurrencyService cs,
|
2017-05-29 04:13:22 +00:00
|
|
|
|
DbService db)
|
2016-09-08 20:27:39 +00:00
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
_bc = bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
_cs = cs;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
_db = db;
|
2016-09-08 20:27:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-08 20:27:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task Pick()
|
2016-09-08 20:27:39 +00:00
|
|
|
|
{
|
2016-12-16 18:43:57 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-09-08 20:27:39 +00:00
|
|
|
|
|
2017-01-05 10:21:38 +00:00
|
|
|
|
if (!(await channel.Guild.GetCurrentUserAsync()).GetPermissions(channel).ManageMessages)
|
2016-09-08 20:27:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
2017-02-13 17:26:58 +00:00
|
|
|
|
try { await Context.Message.DeleteAsync().ConfigureAwait(false); } catch { }
|
2017-10-04 22:51:12 +00:00
|
|
|
|
if (!_service.PlantedFlowers.TryRemove(channel.Id, out List<IUserMessage> msgs))
|
2017-02-13 17:26:58 +00:00
|
|
|
|
return;
|
2016-09-08 20:27:39 +00:00
|
|
|
|
|
2017-02-13 17:26:58 +00:00
|
|
|
|
await Task.WhenAll(msgs.Where(m => m != null).Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false);
|
2016-09-08 20:27:39 +00:00
|
|
|
|
|
2017-07-20 03:10:39 +00:00
|
|
|
|
await _cs.AddAsync((IGuildUser)Context.User, $"Picked {_bc.BotConfig.CurrencyPluralName}", msgs.Count, false).ConfigureAwait(false);
|
|
|
|
|
var msg = await ReplyConfirmLocalized("picked", msgs.Count + _bc.BotConfig.CurrencySign)
|
2017-02-23 22:30:38 +00:00
|
|
|
|
.ConfigureAwait(false);
|
2017-02-13 17:26:58 +00:00
|
|
|
|
msg.DeleteAfter(10);
|
2016-09-08 20:27:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-08 20:27:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-01-23 01:35:53 +00:00
|
|
|
|
public async Task Plant(int amount = 1)
|
2016-09-08 20:27:39 +00:00
|
|
|
|
{
|
2017-01-23 01:35:53 +00:00
|
|
|
|
if (amount < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-07-20 03:10:39 +00:00
|
|
|
|
var removed = await _cs.RemoveAsync((IGuildUser)Context.User, $"Planted a {_bc.BotConfig.CurrencyName}", amount, false).ConfigureAwait(false);
|
2016-09-08 20:27:39 +00:00
|
|
|
|
if (!removed)
|
|
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
|
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
2016-09-08 20:27:39 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-04 22:51:12 +00:00
|
|
|
|
var imgData = _service.GetRandomCurrencyImage();
|
2017-07-27 16:43:15 +00:00
|
|
|
|
|
2017-02-23 22:30:38 +00:00
|
|
|
|
var msgToSend = GetText("planted",
|
2017-03-08 23:58:58 +00:00
|
|
|
|
Format.Bold(Context.User.ToString()),
|
2017-07-20 03:10:39 +00:00
|
|
|
|
amount + _bc.BotConfig.CurrencySign,
|
2017-02-23 22:30:38 +00:00
|
|
|
|
Prefix);
|
2017-02-04 08:34:51 +00:00
|
|
|
|
|
2017-03-08 23:58:58 +00:00
|
|
|
|
if (amount > 1)
|
2017-03-09 02:17:58 +00:00
|
|
|
|
msgToSend += " " + GetText("pick_pl", Prefix);
|
2017-03-08 23:58:58 +00:00
|
|
|
|
else
|
2017-03-09 02:17:58 +00:00
|
|
|
|
msgToSend += " " + GetText("pick_sn", Prefix);
|
2017-03-08 23:58:58 +00:00
|
|
|
|
|
2017-02-04 08:34:51 +00:00
|
|
|
|
IUserMessage msg;
|
2017-05-29 04:13:22 +00:00
|
|
|
|
using (var toSend = imgData.Data.ToStream())
|
2016-09-08 20:27:39 +00:00
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
msg = await Context.Channel.SendFileAsync(toSend, imgData.Name, msgToSend).ConfigureAwait(false);
|
2016-09-08 20:27:39 +00:00
|
|
|
|
}
|
2017-01-23 01:35:53 +00:00
|
|
|
|
|
|
|
|
|
var msgs = new IUserMessage[amount];
|
|
|
|
|
msgs[0] = msg;
|
|
|
|
|
|
2017-10-04 22:51:12 +00:00
|
|
|
|
_service.PlantedFlowers.AddOrUpdate(Context.Channel.Id, msgs.ToList(), (id, old) =>
|
2017-01-23 01:35:53 +00:00
|
|
|
|
{
|
|
|
|
|
old.AddRange(msgs);
|
|
|
|
|
return old;
|
|
|
|
|
});
|
2016-09-08 20:27:39 +00:00
|
|
|
|
}
|
2017-05-15 12:32:40 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-08 20:27:39 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
2017-05-15 12:32:40 +00:00
|
|
|
|
#if GLOBAL_NADEKO
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
#endif
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task GenCurrency()
|
2016-09-08 20:27:39 +00:00
|
|
|
|
{
|
2016-12-16 18:43:57 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-09-08 20:27:39 +00:00
|
|
|
|
|
|
|
|
|
bool enabled;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-09-08 20:27:39 +00:00
|
|
|
|
{
|
2017-06-25 00:35:37 +00:00
|
|
|
|
var guildConfig = uow.GuildConfigs.For(channel.Guild.Id, set => set.Include(gc => gc.GenerateCurrencyChannelIds));
|
2016-09-08 20:27:39 +00:00
|
|
|
|
|
2016-10-11 03:27:36 +00:00
|
|
|
|
var toAdd = new GCChannelId() { ChannelId = channel.Id };
|
2016-10-11 04:21:43 +00:00
|
|
|
|
if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd))
|
2016-09-08 20:27:39 +00:00
|
|
|
|
{
|
2016-10-11 03:27:36 +00:00
|
|
|
|
guildConfig.GenerateCurrencyChannelIds.Add(toAdd);
|
2017-10-04 22:51:12 +00:00
|
|
|
|
_service.GenerationChannels.Add(channel.Id);
|
2016-09-08 20:27:39 +00:00
|
|
|
|
enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-10-11 03:27:36 +00:00
|
|
|
|
guildConfig.GenerateCurrencyChannelIds.Remove(toAdd);
|
2017-10-04 22:51:12 +00:00
|
|
|
|
_service.GenerationChannels.TryRemove(channel.Id);
|
2016-09-08 20:27:39 +00:00
|
|
|
|
enabled = false;
|
|
|
|
|
}
|
2016-09-08 20:57:03 +00:00
|
|
|
|
await uow.CompleteAsync();
|
2016-09-08 20:27:39 +00:00
|
|
|
|
}
|
|
|
|
|
if (enabled)
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyConfirmLocalized("curgen_enabled").ConfigureAwait(false);
|
2016-09-08 20:27:39 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyConfirmLocalized("curgen_disabled").ConfigureAwait(false);
|
2016-09-08 20:27:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|