.bce command added, you can now edit BotConfig without editing the database and restarting the bot. Cleanup
This commit is contained in:
parent
fe88611183
commit
9163510eee
@ -1,7 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Impl;
|
||||
|
||||
namespace NadekoBot.Common.Attributes
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Impl;
|
||||
|
||||
namespace NadekoBot.Common.Attributes
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Impl;
|
||||
|
||||
namespace NadekoBot.Common.Attributes
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Impl;
|
||||
|
||||
namespace NadekoBot.Common.Attributes
|
||||
|
20
src/NadekoBot/Common/BotConfigEditType.cs
Normal file
20
src/NadekoBot/Common/BotConfigEditType.cs
Normal file
@ -0,0 +1,20 @@
|
||||
namespace NadekoBot.Common
|
||||
{
|
||||
public enum BotConfigEditType
|
||||
{
|
||||
CurrencyGenerationChance,
|
||||
CurrencyGenerationCooldown,
|
||||
CurrencyName,
|
||||
CurrencyPluralName,
|
||||
CurrencySign,
|
||||
DmHelpString,
|
||||
HelpString,
|
||||
CurrencyDropAmount,
|
||||
CurrencyDropAmountMax,
|
||||
MinimumBetAmount,
|
||||
TriviaCurrencyReward,
|
||||
|
||||
//ErrorColor, //after i fix the nadekobot.cs static variables
|
||||
//OkColor
|
||||
}
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
|
@ -2,9 +2,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Migrations
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Permissions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
|
@ -5,7 +5,6 @@ using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -29,14 +29,16 @@ namespace NadekoBot.Modules.Administration
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IImagesService _images;
|
||||
private readonly MusicService _music;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
|
||||
public SelfCommands(DbService db, DiscordSocketClient client,
|
||||
MusicService music, IImagesService images)
|
||||
MusicService music, IImagesService images, IBotConfigProvider bc)
|
||||
{
|
||||
_db = db;
|
||||
_client = client;
|
||||
_images = images;
|
||||
_music = music;
|
||||
_bc = bc;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@ -179,9 +181,11 @@ namespace NadekoBot.Modules.Administration
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
var config = uow.BotConfig.GetOrCreate();
|
||||
_service.ForwardDMs = config.ForwardMessages = !config.ForwardMessages;
|
||||
config.ForwardMessages = !config.ForwardMessages;
|
||||
uow.Complete();
|
||||
}
|
||||
_bc.Reload();
|
||||
|
||||
if (_service.ForwardDMs)
|
||||
await ReplyConfirmLocalized("fwdm_start").ConfigureAwait(false);
|
||||
else
|
||||
@ -196,9 +200,11 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
var config = uow.BotConfig.GetOrCreate();
|
||||
lock (_locker)
|
||||
_service.ForwardDMsToAllOwners = config.ForwardToAllOwners = !config.ForwardToAllOwners;
|
||||
config.ForwardToAllOwners = !config.ForwardToAllOwners;
|
||||
uow.Complete();
|
||||
}
|
||||
_bc.Reload();
|
||||
|
||||
if (_service.ForwardDMsToAllOwners)
|
||||
await ReplyConfirmLocalized("fwall_start").ConfigureAwait(false);
|
||||
else
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -8,7 +8,6 @@ using NadekoBot.Common;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Services.Impl;
|
||||
using NLog;
|
||||
|
||||
@ -16,8 +15,9 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
public class SelfService : ILateExecutor, INService
|
||||
{
|
||||
public volatile bool ForwardDMs;
|
||||
public volatile bool ForwardDMsToAllOwners;
|
||||
//todo bot config
|
||||
public bool ForwardDMs => _bc.BotConfig.ForwardMessages;
|
||||
public bool ForwardDMsToAllOwners => _bc.BotConfig.ForwardToAllOwners;
|
||||
|
||||
private readonly NadekoBot _bot;
|
||||
private readonly CommandHandler _cmdHandler;
|
||||
@ -28,9 +28,10 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IBotCredentials _creds;
|
||||
private ImmutableArray<AsyncLazy<IDMChannel>> ownerChannels = new ImmutableArray<AsyncLazy<IDMChannel>>();
|
||||
private readonly IBotConfigProvider _bc;
|
||||
|
||||
public SelfService(DiscordSocketClient client, NadekoBot bot, CommandHandler cmdHandler, DbService db,
|
||||
BotConfig bc, ILocalization localization, NadekoStrings strings, IBotCredentials creds)
|
||||
IBotConfigProvider bc, ILocalization localization, NadekoStrings strings, IBotCredentials creds)
|
||||
{
|
||||
_bot = bot;
|
||||
_cmdHandler = cmdHandler;
|
||||
@ -40,15 +41,13 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_strings = strings;
|
||||
_client = client;
|
||||
_creds = creds;
|
||||
|
||||
ForwardDMs = bc.ForwardMessages;
|
||||
ForwardDMsToAllOwners = bc.ForwardToAllOwners;
|
||||
_bc = bc;
|
||||
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
await bot.Ready.Task.ConfigureAwait(false);
|
||||
|
||||
foreach (var cmd in bc.StartupCommands)
|
||||
foreach (var cmd in bc.BotConfig.StartupCommands)
|
||||
{
|
||||
await cmdHandler.ExecuteExternal(cmd.GuildId, cmd.ChannelId, cmd.CommandText);
|
||||
await Task.Delay(400).ConfigureAwait(false);
|
||||
|
@ -4,7 +4,6 @@ using Discord;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.CustomReactions.Services;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -30,11 +30,11 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly PermissionService _perms;
|
||||
private readonly CommandHandler _cmd;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly NadekoStrings _strings;
|
||||
|
||||
public CustomReactionsService(PermissionService perms, DbService db, NadekoStrings strings,
|
||||
DiscordSocketClient client, CommandHandler cmd, BotConfig bc, IUnitOfWork uow)
|
||||
DiscordSocketClient client, CommandHandler cmd, IBotConfigProvider bc, IUnitOfWork uow)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_db = db;
|
||||
@ -69,7 +69,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
|
||||
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
|
||||
var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant();
|
||||
return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger);
|
||||
return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.BotConfig.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger);
|
||||
}).ToArray();
|
||||
|
||||
if (rs.Length != 0)
|
||||
@ -90,7 +90,7 @@ namespace NadekoBot.Modules.CustomReactions.Services
|
||||
return false;
|
||||
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
|
||||
var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant();
|
||||
return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger);
|
||||
return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.BotConfig.CustomReactionsStartWith && content.StartsWith(trigger + " ")) || content == trigger);
|
||||
}).ToArray();
|
||||
if (grs.Length == 0)
|
||||
return null;
|
||||
|
@ -3,7 +3,6 @@ using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
@ -22,14 +21,14 @@ namespace NadekoBot.Modules.Gambling
|
||||
[Group]
|
||||
public class AnimalRacingCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
|
||||
public static ConcurrentDictionary<ulong, AnimalRace> AnimalRaces { get; } = new ConcurrentDictionary<ulong, AnimalRace>();
|
||||
|
||||
public AnimalRacingCommands(BotConfig bc, CurrencyService cs, DiscordSocketClient client)
|
||||
public AnimalRacingCommands(IBotConfigProvider bc, CurrencyService cs, DiscordSocketClient client)
|
||||
{
|
||||
_bc = bc;
|
||||
_cs = cs;
|
||||
@ -82,7 +81,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
private readonly Logger _log;
|
||||
|
||||
private readonly ITextChannel _raceChannel;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly ILocalization _localization;
|
||||
@ -90,7 +89,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
public bool Started { get; private set; }
|
||||
|
||||
public AnimalRace(ulong serverId, ITextChannel channel, string prefix, BotConfig bc,
|
||||
public AnimalRace(ulong serverId, ITextChannel channel, string prefix, IBotConfigProvider bc,
|
||||
CurrencyService cs, DiscordSocketClient client, ILocalization localization,
|
||||
NadekoStrings strings)
|
||||
{
|
||||
@ -110,7 +109,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
return;
|
||||
}
|
||||
|
||||
animals = new ConcurrentQueue<string>(_bc.RaceAnimals.Select(ra => ra.Icon).Shuffle());
|
||||
animals = new ConcurrentQueue<string>(_bc.BotConfig.RaceAnimals.Select(ra => ra.Icon).Shuffle());
|
||||
|
||||
|
||||
var cancelSource = new CancellationTokenSource();
|
||||
@ -238,7 +237,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
.ConfigureAwait(false);
|
||||
await _raceChannel.SendConfirmAsync(GetText("animal_race"),
|
||||
Format.Bold(GetText("animal_race_won_money", winner.User.Mention,
|
||||
winner.Animal, wonAmount + _bc.CurrencySign)))
|
||||
winner.Animal, wonAmount + _bc.BotConfig.CurrencySign)))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
@ -295,13 +294,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
if (amount > 0)
|
||||
if (!await _cs.RemoveAsync(u, "BetRace", amount, false).ConfigureAwait(false))
|
||||
{
|
||||
await _raceChannel.SendErrorAsync(GetText("not_enough", _bc.CurrencySign)).ConfigureAwait(false);
|
||||
await _raceChannel.SendErrorAsync(GetText("not_enough", _bc.BotConfig.CurrencySign)).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
_participants.Add(p);
|
||||
string confStr;
|
||||
if (amount > 0)
|
||||
confStr = GetText("animal_race_join_bet", u.Mention, p.Animal, amount + _bc.CurrencySign);
|
||||
confStr = GetText("animal_race_join_bet", u.Mention, p.Animal, amount + _bc.BotConfig.CurrencySign);
|
||||
else
|
||||
confStr = GetText("animal_race_join", u.Mention, p.Animal);
|
||||
await _raceChannel.SendConfirmAsync(GetText("animal_race"), Format.Bold(confStr)).ConfigureAwait(false);
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common
|
||||
{
|
||||
|
@ -3,7 +3,6 @@ using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.WebSocket;
|
||||
@ -12,7 +11,6 @@ using NadekoBot.Common;
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NLog;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
@ -37,10 +35,10 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
private string _secretCode = string.Empty;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
public CurrencyEventsCommands(DiscordSocketClient client, BotConfig bc, CurrencyService cs)
|
||||
public CurrencyEventsCommands(DiscordSocketClient client, IBotConfigProvider bc, CurrencyService cs)
|
||||
{
|
||||
_client = client;
|
||||
_bc = bc;
|
||||
@ -80,12 +78,12 @@ namespace NadekoBot.Modules.Gambling
|
||||
_secretCode += _sneakyGameStatusChars[rng.Next(0, _sneakyGameStatusChars.Length)];
|
||||
}
|
||||
|
||||
await _client.SetGameAsync($"type {_secretCode} for " + _bc.CurrencyPluralName)
|
||||
await _client.SetGameAsync($"type {_secretCode} for " + _bc.BotConfig.CurrencyPluralName)
|
||||
.ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
var title = GetText("sneakygamestatus_title");
|
||||
var desc = GetText("sneakygamestatus_desc", Format.Bold(100.ToString()) + _bc.CurrencySign, Format.Bold(num.ToString()));
|
||||
var desc = GetText("sneakygamestatus_desc", Format.Bold(100.ToString()) + _bc.BotConfig.CurrencySign, Format.Bold(num.ToString()));
|
||||
await context.Channel.SendConfirmAsync(title, desc).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
@ -133,7 +131,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
amount = 100;
|
||||
|
||||
var title = GetText("flowerreaction_title");
|
||||
var desc = GetText("flowerreaction_desc", "🌸", Format.Bold(amount.ToString()) + _bc.CurrencySign);
|
||||
var desc = GetText("flowerreaction_desc", "🌸", Format.Bold(amount.ToString()) + _bc.BotConfig.CurrencySign);
|
||||
var footer = GetText("flowerreaction_footer", 24);
|
||||
var msg = await context.Channel.SendConfirmAsync(title,
|
||||
desc, footer: footer)
|
||||
|
@ -2,7 +2,6 @@ using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@ -19,12 +18,12 @@ namespace NadekoBot.Modules.Gambling
|
||||
public class FlipCoinCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly IImagesService _images;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
private readonly NadekoRandom rng = new NadekoRandom();
|
||||
|
||||
public FlipCoinCommands(IImagesService images, CurrencyService cs, BotConfig bc)
|
||||
public FlipCoinCommands(IImagesService images, CurrencyService cs, IBotConfigProvider bc)
|
||||
{
|
||||
_images = images;
|
||||
_bc = bc;
|
||||
@ -89,15 +88,15 @@ namespace NadekoBot.Modules.Gambling
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task Betflip(int amount, BetFlipGuess guess)
|
||||
{
|
||||
if (amount < _bc.MinimumBetAmount)
|
||||
if (amount < _bc.BotConfig.MinimumBetAmount)
|
||||
{
|
||||
await ReplyErrorLocalized("min_bet_limit", _bc.MinimumBetAmount + _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("min_bet_limit", _bc.BotConfig.MinimumBetAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var removed = await _cs.RemoveAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false);
|
||||
if (!removed)
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", _bc.CurrencyPluralName).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencyPluralName).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
BetFlipGuess result;
|
||||
@ -116,8 +115,8 @@ namespace NadekoBot.Modules.Gambling
|
||||
string str;
|
||||
if (guess == result)
|
||||
{
|
||||
var toWin = (int)Math.Round(amount * _bc.BetflipMultiplier);
|
||||
str = Context.User.Mention + " " + GetText("flip_guess", toWin + _bc.CurrencySign);
|
||||
var toWin = (int)Math.Round(amount * _bc.BotConfig.BetflipMultiplier);
|
||||
str = Context.User.Mention + " " + GetText("flip_guess", toWin + _bc.BotConfig.CurrencySign);
|
||||
await _cs.AddAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
|
@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
[Group]
|
||||
public class FlowerShopCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly DbService _db;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DiscordSocketClient _client;
|
||||
@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
List
|
||||
}
|
||||
|
||||
public FlowerShopCommands(BotConfig bc, DbService db, CurrencyService cs, DiscordSocketClient client)
|
||||
public FlowerShopCommands(IBotConfigProvider bc, DbService db, CurrencyService cs, DiscordSocketClient client)
|
||||
{
|
||||
_db = db;
|
||||
_bc = bc;
|
||||
@ -65,12 +65,12 @@ namespace NadekoBot.Modules.Gambling
|
||||
return new EmbedBuilder().WithErrorColor()
|
||||
.WithDescription(GetText("shop_none"));
|
||||
var embed = new EmbedBuilder().WithOkColor()
|
||||
.WithTitle(GetText("shop", _bc.CurrencySign));
|
||||
.WithTitle(GetText("shop", _bc.BotConfig.CurrencySign));
|
||||
|
||||
for (int i = 0; i < theseEntries.Length; i++)
|
||||
{
|
||||
var entry = entries[i];
|
||||
embed.AddField(efb => efb.WithName($"#{curPage * 9 + i + 1} - {entry.Price}{_bc.CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true));
|
||||
embed.AddField(efb => efb.WithName($"#{curPage * 9 + i + 1} - {entry.Price}{_bc.BotConfig.CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true));
|
||||
}
|
||||
return embed;
|
||||
}, entries.Count / 9, true);
|
||||
@ -130,7 +130,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -186,7 +186,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -13,15 +13,15 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
public partial class Gambling : NadekoTopLevelModule
|
||||
{
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly DbService _db;
|
||||
private readonly CurrencyService _currency;
|
||||
|
||||
private string CurrencyName => _bc.CurrencyName;
|
||||
private string CurrencyPluralName => _bc.CurrencyPluralName;
|
||||
private string CurrencySign => _bc.CurrencySign;
|
||||
private string CurrencyName => _bc.BotConfig.CurrencyName;
|
||||
private string CurrencyPluralName => _bc.BotConfig.CurrencyPluralName;
|
||||
private string CurrencySign => _bc.BotConfig.CurrencySign;
|
||||
|
||||
public Gambling(BotConfig bc, DbService db, CurrencyService currency)
|
||||
public Gambling(IBotConfigProvider bc, DbService db, CurrencyService currency)
|
||||
{
|
||||
_bc = bc;
|
||||
_db = db;
|
||||
@ -230,21 +230,21 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
if (rnd < 91)
|
||||
{
|
||||
str += GetText("br_win", (amount * _bc.Betroll67Multiplier) + CurrencySign, 66);
|
||||
str += GetText("br_win", (amount * _bc.BotConfig.Betroll67Multiplier) + CurrencySign, 66);
|
||||
await _currency.AddAsync(Context.User, "Betroll Gamble",
|
||||
(int) (amount * _bc.Betroll67Multiplier), false).ConfigureAwait(false);
|
||||
(int) (amount * _bc.BotConfig.Betroll67Multiplier), false).ConfigureAwait(false);
|
||||
}
|
||||
else if (rnd < 100)
|
||||
{
|
||||
str += GetText("br_win", (amount * _bc.Betroll91Multiplier) + CurrencySign, 90);
|
||||
str += GetText("br_win", (amount * _bc.BotConfig.Betroll91Multiplier) + CurrencySign, 90);
|
||||
await _currency.AddAsync(Context.User, "Betroll Gamble",
|
||||
(int) (amount * _bc.Betroll91Multiplier), false).ConfigureAwait(false);
|
||||
(int) (amount * _bc.BotConfig.Betroll91Multiplier), false).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
str += GetText("br_win", (amount * _bc.Betroll100Multiplier) + CurrencySign, 100) + " 👑";
|
||||
str += GetText("br_win", (amount * _bc.BotConfig.Betroll100Multiplier) + CurrencySign, 100) + " 👑";
|
||||
await _currency.AddAsync(Context.User, "Betroll Gamble",
|
||||
(int) (amount * _bc.Betroll100Multiplier), false).ConfigureAwait(false);
|
||||
(int) (amount * _bc.BotConfig.Betroll100Multiplier), false).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
await Context.Channel.SendConfirmAsync(str).ConfigureAwait(false);
|
||||
|
@ -3,7 +3,6 @@ using Discord.Commands;
|
||||
using ImageSharp;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -25,7 +24,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
private static int _totalPaidOut;
|
||||
|
||||
private static readonly HashSet<ulong> _runningUsers = new HashSet<ulong>();
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
|
||||
private const int _alphaCutOut = byte.MaxValue / 3;
|
||||
|
||||
@ -36,7 +35,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
private readonly IImagesService _images;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
public SlotCommands(IImagesService images, BotConfig bc, CurrencyService cs)
|
||||
public SlotCommands(IImagesService images, IBotConfigProvider bc, CurrencyService cs)
|
||||
{
|
||||
_images = images;
|
||||
_bc = bc;
|
||||
@ -148,20 +147,20 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
if (amount < 1)
|
||||
{
|
||||
await ReplyErrorLocalized("min_bet_limit", 1 + _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("min_bet_limit", 1 + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
const int maxAmount = 9999;
|
||||
if (amount > maxAmount)
|
||||
{
|
||||
GetText("slot_maxbet", maxAmount + _bc.CurrencySign);
|
||||
await ReplyErrorLocalized("max_bet_limit", maxAmount + _bc.CurrencySign).ConfigureAwait(false);
|
||||
GetText("slot_maxbet", maxAmount + _bc.BotConfig.CurrencySign);
|
||||
await ReplyErrorLocalized("max_bet_limit", maxAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await _cs.RemoveAsync(Context.User, "Slot Machine", amount, false))
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
Interlocked.Add(ref _totalBet, amount);
|
||||
@ -214,16 +213,16 @@ namespace NadekoBot.Modules.Gambling
|
||||
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);
|
||||
msg = GetText("slot_single", _bc.BotConfig.CurrencySign, 1);
|
||||
else if (result.Multiplier == 4)
|
||||
msg = GetText("slot_two", _bc.CurrencySign, 4);
|
||||
msg = GetText("slot_two", _bc.BotConfig.CurrencySign, 4);
|
||||
else if (result.Multiplier == 10)
|
||||
msg = GetText("slot_three", 10);
|
||||
else if (result.Multiplier == 30)
|
||||
msg = GetText("slot_jackpot", 30);
|
||||
}
|
||||
|
||||
await Context.Channel.SendFileAsync(bgImage.ToStream(), "result.png", Context.User.Mention + " " + msg + $"\n`{GetText("slot_bet")}:`{amount} `{GetText("slot_won")}:` {amount * result.Multiplier}{_bc.CurrencySign}").ConfigureAwait(false);
|
||||
await Context.Channel.SendFileAsync(bgImage.ToStream(), "result.png", Context.User.Mention + " " + msg + $"\n`{GetText("slot_bet")}:`{amount} `{GetText("slot_won")}:` {amount * result.Multiplier}{_bc.BotConfig.CurrencySign}").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
InsufficientAmount
|
||||
}
|
||||
|
||||
public WaifuClaimCommands(BotConfig bc, CurrencyService cs, DbService db)
|
||||
public WaifuClaimCommands(IBotConfigProvider bc, CurrencyService cs, DbService db)
|
||||
{
|
||||
_bc = bc;
|
||||
_cs = cs;
|
||||
@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
if (amount < 50)
|
||||
{
|
||||
await ReplyErrorLocalized("waifu_isnt_cheap", 50 + _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("waifu_isnt_cheap", 50 + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -173,14 +173,14 @@ namespace NadekoBot.Modules.Gambling
|
||||
}
|
||||
if (result == WaifuClaimResult.NotEnoughFunds)
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var msg = GetText("waifu_claimed",
|
||||
Format.Bold(target.ToString()),
|
||||
amount + _bc.CurrencySign);
|
||||
amount + _bc.BotConfig.CurrencySign);
|
||||
if (w.Affinity?.UserId == Context.User.Id)
|
||||
msg += "\n" + GetText("waifu_fulfilled", target, w.Price + _bc.CurrencySign);
|
||||
msg += "\n" + GetText("waifu_fulfilled", target, w.Price + _bc.BotConfig.CurrencySign);
|
||||
else
|
||||
msg = " " + msg;
|
||||
await Context.Channel.SendConfirmAsync(Context.User.Mention + msg).ConfigureAwait(false);
|
||||
@ -258,11 +258,11 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
if (result == DivorceResult.SucessWithPenalty)
|
||||
{
|
||||
await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
}
|
||||
else if (result == DivorceResult.Success)
|
||||
{
|
||||
await ReplyConfirmLocalized("waifu_divorced_notlike", amount + _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("waifu_divorced_notlike", amount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
}
|
||||
else if (result == DivorceResult.NotYourWife)
|
||||
{
|
||||
@ -278,7 +278,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
}
|
||||
|
||||
private static readonly TimeSpan _affinityLimit = TimeSpan.FromMinutes(30);
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DbService _db;
|
||||
|
||||
@ -406,7 +406,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
var w = waifus[i];
|
||||
|
||||
var j = i;
|
||||
embed.AddField(efb => efb.WithName("#" + ((page * 9) + j + 1) + " - " + w.Price + _bc.CurrencySign).WithValue(w.ToString()).WithIsInline(false));
|
||||
embed.AddField(efb => efb.WithName("#" + ((page * 9) + j + 1) + " - " + w.Price + _bc.BotConfig.CurrencySign).WithValue(w.ToString()).WithIsInline(false));
|
||||
}
|
||||
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
@ -2,7 +2,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Common
|
||||
|
@ -7,7 +7,6 @@ using Discord;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
||||
|
@ -7,7 +7,6 @@ using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Impl;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Common
|
||||
|
@ -10,7 +10,6 @@ using Discord.Net;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Services.Impl;
|
||||
using NLog;
|
||||
|
||||
@ -22,7 +21,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
private readonly Logger _log;
|
||||
private readonly NadekoStrings _strings;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
public IGuild Guild { get; }
|
||||
@ -44,7 +43,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
|
||||
public int WinRequirement { get; }
|
||||
|
||||
public TriviaGame(NadekoStrings strings, DiscordSocketClient client, BotConfig bc,
|
||||
public TriviaGame(NadekoStrings strings, DiscordSocketClient client, IBotConfigProvider bc,
|
||||
CurrencyService cs, IGuild guild, ITextChannel channel,
|
||||
bool showHints, int winReq, bool isPokemon)
|
||||
{
|
||||
@ -232,7 +231,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
var reward = _bc.TriviaCurrencyReward;
|
||||
var reward = _bc.BotConfig.TriviaCurrencyReward;
|
||||
if (reward > 0)
|
||||
await _cs.AddAsync(guildUser, "Won trivia", reward, true).ConfigureAwait(false);
|
||||
return;
|
||||
|
@ -5,7 +5,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Common.Trivia
|
||||
|
@ -8,7 +8,6 @@ using Discord.WebSocket;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Games.Services;
|
||||
using NadekoBot.Services;
|
||||
using NLog;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Common
|
||||
|
@ -25,11 +25,11 @@ namespace NadekoBot.Modules.Games
|
||||
public class PlantPickCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly GamesService _games;
|
||||
private readonly DbService _db;
|
||||
|
||||
public PlantPickCommands(BotConfig bc, CurrencyService cs, GamesService games,
|
||||
public PlantPickCommands(IBotConfigProvider bc, CurrencyService cs, GamesService games,
|
||||
DbService db)
|
||||
{
|
||||
_bc = bc;
|
||||
@ -54,8 +54,8 @@ namespace NadekoBot.Modules.Games
|
||||
|
||||
await Task.WhenAll(msgs.Where(m => m != null).Select(toDelete => toDelete.DeleteAsync())).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)
|
||||
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)
|
||||
.ConfigureAwait(false);
|
||||
msg.DeleteAfter(10);
|
||||
}
|
||||
@ -67,10 +67,10 @@ namespace NadekoBot.Modules.Games
|
||||
if (amount < 1)
|
||||
return;
|
||||
|
||||
var removed = await _cs.RemoveAsync((IGuildUser)Context.User, $"Planted a {_bc.CurrencyName}", amount, false).ConfigureAwait(false);
|
||||
var removed = await _cs.RemoveAsync((IGuildUser)Context.User, $"Planted a {_bc.BotConfig.CurrencyName}", amount, false).ConfigureAwait(false);
|
||||
if (!removed)
|
||||
{
|
||||
await ReplyErrorLocalized("not_enough", _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ namespace NadekoBot.Modules.Games
|
||||
//todo 81 upload all currency images to transfer.sh and use that one as cdn
|
||||
var msgToSend = GetText("planted",
|
||||
Format.Bold(Context.User.ToString()),
|
||||
amount + _bc.CurrencySign,
|
||||
amount + _bc.BotConfig.CurrencySign,
|
||||
Prefix);
|
||||
|
||||
if (amount > 1)
|
||||
|
@ -22,7 +22,7 @@ namespace NadekoBot.Modules.Games.Services
|
||||
{
|
||||
public class GamesService : INService
|
||||
{
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
|
||||
public readonly ConcurrentDictionary<ulong, GirlRating> GirlRatings = new ConcurrentDictionary<ulong, GirlRating>();
|
||||
public readonly ImmutableArray<string> EightBallResponses;
|
||||
@ -38,7 +38,7 @@ namespace NadekoBot.Modules.Games.Services
|
||||
|
||||
public List<TypingArticle> TypingArticles { get; } = new List<TypingArticle>();
|
||||
|
||||
public GamesService(DiscordSocketClient client, BotConfig bc, IEnumerable<GuildConfig> gcs,
|
||||
public GamesService(DiscordSocketClient client, IBotConfigProvider bc, IEnumerable<GuildConfig> gcs,
|
||||
NadekoStrings strings, IImagesService images, CommandHandler cmdHandler)
|
||||
{
|
||||
_bc = bc;
|
||||
@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Games.Services
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
//8ball
|
||||
EightBallResponses = _bc.EightBallResponses.Select(ebr => ebr.Text).ToImmutableArray();
|
||||
EightBallResponses = _bc.BotConfig.EightBallResponses.Select(ebr => ebr.Text).ToImmutableArray();
|
||||
|
||||
//girl ratings
|
||||
_t = new Timer((_) =>
|
||||
@ -122,14 +122,14 @@ namespace NadekoBot.Modules.Games.Services
|
||||
var lastGeneration = LastGenerations.GetOrAdd(channel.Id, DateTime.MinValue);
|
||||
var rng = new NadekoRandom();
|
||||
|
||||
if (DateTime.UtcNow - TimeSpan.FromSeconds(_bc.CurrencyGenerationCooldown) < lastGeneration) //recently generated in this channel, don't generate again
|
||||
if (DateTime.UtcNow - TimeSpan.FromSeconds(_bc.BotConfig.CurrencyGenerationCooldown) < lastGeneration) //recently generated in this channel, don't generate again
|
||||
return;
|
||||
|
||||
var num = rng.Next(1, 101) + _bc.CurrencyGenerationChance * 100;
|
||||
var num = rng.Next(1, 101) + _bc.BotConfig.CurrencyGenerationChance * 100;
|
||||
if (num > 100 && LastGenerations.TryUpdate(channel.Id, DateTime.UtcNow, lastGeneration))
|
||||
{
|
||||
var dropAmount = _bc.CurrencyDropAmount;
|
||||
var dropAmountMax = _bc.CurrencyDropAmountMax;
|
||||
var dropAmount = _bc.BotConfig.CurrencyDropAmount;
|
||||
var dropAmountMax = _bc.BotConfig.CurrencyDropAmountMax;
|
||||
|
||||
if (dropAmountMax != null && dropAmountMax > dropAmount)
|
||||
dropAmount = new NadekoRandom().Next(dropAmount, dropAmountMax.Value + 1);
|
||||
@ -139,9 +139,9 @@ namespace NadekoBot.Modules.Games.Services
|
||||
var msgs = new IUserMessage[dropAmount];
|
||||
var prefix = _cmdHandler.GetPrefix(channel.Guild.Id);
|
||||
var toSend = dropAmount == 1
|
||||
? GetText(channel, "curgen_sn", _bc.CurrencySign)
|
||||
? GetText(channel, "curgen_sn", _bc.BotConfig.CurrencySign)
|
||||
+ " " + GetText(channel, "pick_sn", prefix)
|
||||
: GetText(channel, "curgen_pl", dropAmount, _bc.CurrencySign)
|
||||
: GetText(channel, "curgen_pl", dropAmount, _bc.BotConfig.CurrencySign)
|
||||
+ " " + GetText(channel, "pick_pl", prefix);
|
||||
var file = GetRandomCurrencyImage();
|
||||
using (var fileStream = file.Data.ToStream())
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
@ -3,13 +3,11 @@ using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Modules.Games.Common.Trivia;
|
||||
|
||||
|
||||
namespace NadekoBot.Modules.Games
|
||||
{
|
||||
public partial class Games
|
||||
@ -19,11 +17,11 @@ namespace NadekoBot.Modules.Games
|
||||
{
|
||||
private readonly CurrencyService _cs;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
|
||||
public static ConcurrentDictionary<ulong, TriviaGame> RunningTrivias { get; } = new ConcurrentDictionary<ulong, TriviaGame>();
|
||||
|
||||
public TriviaCommands(DiscordSocketClient client, BotConfig bc, CurrencyService cs)
|
||||
public TriviaCommands(DiscordSocketClient client, IBotConfigProvider bc, CurrencyService cs)
|
||||
{
|
||||
_cs = cs;
|
||||
_client = client;
|
||||
|
@ -9,7 +9,6 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Modules.Help.Services;
|
||||
using NadekoBot.Modules.Permissions.Services;
|
||||
|
||||
@ -20,14 +19,14 @@ namespace NadekoBot.Modules.Help
|
||||
public const string PatreonUrl = "https://patreon.com/nadekobot";
|
||||
public const string PaypalUrl = "https://paypal.me/Kwoth";
|
||||
private readonly IBotCredentials _creds;
|
||||
private readonly BotConfig _config;
|
||||
private readonly IBotConfigProvider _config;
|
||||
private readonly CommandService _cmds;
|
||||
private readonly GlobalPermissionService _perms;
|
||||
|
||||
public string HelpString => String.Format(_config.HelpString, _creds.ClientId, Prefix);
|
||||
public string DMHelpString => _config.DMHelpString;
|
||||
public string HelpString => String.Format(_config.BotConfig.HelpString, _creds.ClientId, Prefix);
|
||||
public string DMHelpString => _config.BotConfig.DMHelpString;
|
||||
|
||||
public Help(IBotCredentials creds, GlobalPermissionService perms, BotConfig config, CommandService cmds)
|
||||
public Help(IBotCredentials creds, GlobalPermissionService perms, IBotConfigProvider config, CommandService cmds)
|
||||
{
|
||||
_creds = creds;
|
||||
_config = config;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using System;
|
||||
@ -15,11 +14,11 @@ namespace NadekoBot.Modules.Help.Services
|
||||
{
|
||||
public class HelpService : ILateExecutor, INService
|
||||
{
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly CommandHandler _ch;
|
||||
private readonly NadekoStrings _strings;
|
||||
|
||||
public HelpService(BotConfig bc, CommandHandler ch, NadekoStrings strings)
|
||||
public HelpService(IBotConfigProvider bc, CommandHandler ch, NadekoStrings strings)
|
||||
{
|
||||
_bc = bc;
|
||||
_ch = ch;
|
||||
@ -31,7 +30,7 @@ namespace NadekoBot.Modules.Help.Services
|
||||
try
|
||||
{
|
||||
if(guild == null)
|
||||
await msg.Channel.SendMessageAsync(_bc.DMHelpString).ConfigureAwait(false);
|
||||
await msg.Channel.SendMessageAsync(_bc.BotConfig.DMHelpString).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -2,13 +2,8 @@
|
||||
|
||||
namespace NadekoBot.Modules.Music.Common.Exceptions
|
||||
{
|
||||
// todo use this
|
||||
public class NotInVoiceChannelException : Exception
|
||||
{
|
||||
public NotInVoiceChannelException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public NotInVoiceChannelException() : base("You're not in the voice channel on this server.") { }
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using System.Linq;
|
||||
using System.Collections.Concurrent;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Diagnostics;
|
||||
using NadekoBot.Common.Collections;
|
||||
|
@ -1,10 +1,8 @@
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Music.Common.Exceptions;
|
||||
using NadekoBot.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common;
|
||||
|
||||
|
@ -8,7 +8,6 @@ using System.Linq;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using NadekoBot.Common;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
@ -88,7 +87,7 @@ namespace NadekoBot.Modules.Music.Services
|
||||
{
|
||||
await textCh.SendErrorAsync(GetText("must_be_in_voice")).ConfigureAwait(false);
|
||||
}
|
||||
throw new ArgumentException(nameof(voiceCh));
|
||||
throw new NotInVoiceChannelException();
|
||||
}
|
||||
_log.Info("Get or add");
|
||||
return MusicPlayers.GetOrAdd(guildId, _ =>
|
||||
|
@ -4,7 +4,6 @@ using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Services;
|
||||
using System.Net.Http;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Threading;
|
||||
|
@ -5,7 +5,6 @@ using NadekoBot.Services;
|
||||
using NLog;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Services.Impl;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
|
@ -4,7 +4,6 @@ using Discord.WebSocket;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common.Attributes;
|
||||
|
@ -7,7 +7,6 @@ using Discord;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Collections.Generic;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Common.TypeReaders;
|
||||
using NadekoBot.Common.TypeReaders.Models;
|
||||
|
@ -1,7 +1,5 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Modules.Permissions.Services;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using NadekoBot.Common.Collections;
|
||||
@ -15,9 +14,9 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
public ConcurrentHashSet<ulong> BlacklistedGuilds { get; }
|
||||
public ConcurrentHashSet<ulong> BlacklistedChannels { get; }
|
||||
|
||||
public BlacklistService(BotConfig bc)
|
||||
public BlacklistService(IBotConfigProvider bc)
|
||||
{
|
||||
var blacklist = bc.Blacklist;
|
||||
var blacklist = bc.BotConfig.Blacklist;
|
||||
BlacklistedUsers = new ConcurrentHashSet<ulong>(blacklist.Where(bi => bi.Type == BlacklistType.User).Select(c => c.ItemId));
|
||||
BlacklistedGuilds = new ConcurrentHashSet<ulong>(blacklist.Where(bi => bi.Type == BlacklistType.Server).Select(c => c.ItemId));
|
||||
BlacklistedChannels = new ConcurrentHashSet<ulong>(blacklist.Where(bi => bi.Type == BlacklistType.Channel).Select(c => c.ItemId));
|
||||
|
@ -1,12 +1,10 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Permissions.Services
|
||||
{
|
||||
@ -15,10 +13,10 @@ namespace NadekoBot.Modules.Permissions.Services
|
||||
public readonly ConcurrentHashSet<string> BlockedModules;
|
||||
public readonly ConcurrentHashSet<string> BlockedCommands;
|
||||
|
||||
public GlobalPermissionService(BotConfig bc)
|
||||
public GlobalPermissionService(IBotConfigProvider bc)
|
||||
{
|
||||
BlockedModules = new ConcurrentHashSet<string>(bc.BlockedModules.Select(x => x.Name));
|
||||
BlockedCommands = new ConcurrentHashSet<string>(bc.BlockedCommands.Select(x => x.Name));
|
||||
BlockedModules = new ConcurrentHashSet<string>(bc.BotConfig.BlockedModules.Select(x => x.Name));
|
||||
BlockedCommands = new ConcurrentHashSet<string>(bc.BotConfig.BlockedCommands.Select(x => x.Name));
|
||||
}
|
||||
|
||||
public async Task<bool> TryBlockLate(DiscordSocketClient client, IUserMessage msg, IGuild guild, IMessageChannel channel, IUser user, string moduleName, string commandName)
|
||||
|
@ -16,10 +16,10 @@ namespace NadekoBot.Modules.Pokemon
|
||||
public class Pokemon : NadekoTopLevelModule<PokemonService>
|
||||
{
|
||||
private readonly DbService _db;
|
||||
private readonly BotConfig _bc;
|
||||
private readonly IBotConfigProvider _bc;
|
||||
private readonly CurrencyService _cs;
|
||||
|
||||
public Pokemon(DbService db, BotConfig bc, CurrencyService cs)
|
||||
public Pokemon(DbService db, IBotConfigProvider bc, CurrencyService cs)
|
||||
{
|
||||
_db = db;
|
||||
_bc = bc;
|
||||
@ -230,7 +230,7 @@ namespace NadekoBot.Modules.Pokemon
|
||||
{
|
||||
if (!await _cs.RemoveAsync(user, $"Poke-Heal {target}", amount, true).ConfigureAwait(false))
|
||||
{
|
||||
await ReplyErrorLocalized("no_currency", _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("no_currency", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -243,13 +243,13 @@ namespace NadekoBot.Modules.Pokemon
|
||||
_service.Stats[targetUser.Id].Hp = (targetStats.MaxHp / 2);
|
||||
if (target == "yourself")
|
||||
{
|
||||
await ReplyConfirmLocalized("revive_yourself", _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("revive_yourself", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await ReplyConfirmLocalized("revive_other", Format.Bold(targetUser.ToString()), _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("revive_other", Format.Bold(targetUser.ToString()), _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
}
|
||||
await ReplyConfirmLocalized("healed", Format.Bold(targetUser.ToString()), _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("healed", Format.Bold(targetUser.ToString()), _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -296,7 +296,7 @@ namespace NadekoBot.Modules.Pokemon
|
||||
{
|
||||
if (!await _cs.RemoveAsync(user, $"{user} change type to {typeTargeted}", amount, true).ConfigureAwait(false))
|
||||
{
|
||||
await ReplyErrorLocalized("no_currency", _bc.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyErrorLocalized("no_currency", _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -330,7 +330,7 @@ namespace NadekoBot.Modules.Pokemon
|
||||
//Now for the response
|
||||
await ReplyConfirmLocalized("settype_success",
|
||||
targetType,
|
||||
_bc.CurrencySign).ConfigureAwait(false);
|
||||
_bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Searches.Services;
|
||||
using NadekoBot.Services;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
|
@ -1,7 +1,5 @@
|
||||
using Discord;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -1,6 +1,5 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common;
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
39
src/NadekoBot/Modules/Utility/BotConfigCommands.cs
Normal file
39
src/NadekoBot/Modules/Utility/BotConfigCommands.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Services;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Utility
|
||||
{
|
||||
public partial class Utility
|
||||
{
|
||||
public class BotConfigCommands : NadekoSubmodule<IBotConfigProvider>
|
||||
{
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public async Task BotConfigEdit()
|
||||
{
|
||||
var names = Enum.GetNames(typeof(BotConfigEditType));
|
||||
await ReplyAsync(string.Join(", ", names)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public async Task BotConfigEdit(BotConfigEditType type, [Remainder]string newValue = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(newValue))
|
||||
newValue = null;
|
||||
|
||||
var success = _service.Edit(type, newValue);
|
||||
|
||||
if (!success)
|
||||
await ReplyErrorLocalized("bot_config_edit_fail", Format.Bold(type.ToString()), Format.Bold(newValue ?? "NULL")).ConfigureAwait(false);
|
||||
else
|
||||
await ReplyConfirmLocalized("bot_config_edit_success", Format.Bold(type.ToString()), Format.Bold(newValue ?? "NULL")).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Utility.Common.Exceptions
|
||||
{
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Utility.Common.Exceptions
|
||||
{
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Discord.Commands;
|
||||
using System;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Extensions;
|
||||
using Discord;
|
||||
using NadekoBot.Common.Attributes;
|
||||
@ -16,11 +15,11 @@ namespace NadekoBot.Modules.Utility
|
||||
public class PatreonCommands : NadekoSubmodule<PatreonRewardsService>
|
||||
{
|
||||
private readonly IBotCredentials _creds;
|
||||
private readonly BotConfig _config;
|
||||
private readonly IBotConfigProvider _config;
|
||||
private readonly DbService _db;
|
||||
private readonly CurrencyService _currency;
|
||||
|
||||
public PatreonCommands(IBotCredentials creds, BotConfig config, DbService db, CurrencyService currency)
|
||||
public PatreonCommands(IBotCredentials creds, IBotConfigProvider config, DbService db, CurrencyService currency)
|
||||
{
|
||||
_creds = creds;
|
||||
_config = config;
|
||||
@ -64,7 +63,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
if (amount > 0)
|
||||
{
|
||||
await ReplyConfirmLocalized("clpa_success", amount + _config.CurrencySign).ConfigureAwait(false);
|
||||
await ReplyConfirmLocalized("clpa_success", amount + _config.BotConfig.CurrencySign).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var rem = (_service.Interval - (DateTime.UtcNow - _service.LastUpdate));
|
||||
|
@ -3,7 +3,6 @@ using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -25,11 +25,11 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
private readonly Logger _log;
|
||||
private readonly CancellationTokenSource cancelSource;
|
||||
private readonly CancellationToken cancelAllToken;
|
||||
private readonly BotConfig _config;
|
||||
private readonly IBotConfigProvider _config;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly DbService _db;
|
||||
|
||||
public RemindService(DiscordSocketClient client, BotConfig config, DbService db,
|
||||
public RemindService(DiscordSocketClient client, IBotConfigProvider config, DbService db,
|
||||
StartingGuildsService guilds, IUnitOfWork uow)
|
||||
{
|
||||
_config = config;
|
||||
@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Utility.Services
|
||||
cancelAllToken = cancelSource.Token;
|
||||
|
||||
var reminders = uow.Reminders.GetIncludedReminders(guilds).ToList();
|
||||
RemindMessageFormat = _config.RemindMessageFormat;
|
||||
RemindMessageFormat = _config.BotConfig.RemindMessageFormat;
|
||||
|
||||
foreach (var r in reminders)
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
|
@ -8,7 +8,6 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Modules.Permissions;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
@ -34,7 +33,6 @@ namespace NadekoBot
|
||||
public CommandService CommandService { get; }
|
||||
|
||||
public DbService Db { get; }
|
||||
public BotConfig BotConfig { get; }
|
||||
public ImmutableArray<GuildConfig> AllGuildConfigs { get; private set; }
|
||||
|
||||
/* I don't know how to make this not be static
|
||||
@ -54,6 +52,8 @@ namespace NadekoBot
|
||||
|
||||
private readonly ShardComClient _comClient;
|
||||
|
||||
private readonly BotConfig _botConfig;
|
||||
|
||||
public NadekoBot(int shardId, int parentProcessId, int? port = null)
|
||||
{
|
||||
if (shardId < 0)
|
||||
@ -85,9 +85,9 @@ namespace NadekoBot
|
||||
|
||||
using (var uow = Db.UnitOfWork)
|
||||
{
|
||||
BotConfig = uow.BotConfig.GetOrCreate();
|
||||
OkColor = new Color(Convert.ToUInt32(BotConfig.OkColor, 16));
|
||||
ErrorColor = new Color(Convert.ToUInt32(BotConfig.ErrorColor, 16));
|
||||
_botConfig = uow.BotConfig.GetOrCreate();
|
||||
OkColor = new Color(Convert.ToUInt32(_botConfig.OkColor, 16));
|
||||
ErrorColor = new Color(Convert.ToUInt32(_botConfig.ErrorColor, 16));
|
||||
}
|
||||
|
||||
SetupShard(parentProcessId, port.Value);
|
||||
@ -124,13 +124,13 @@ namespace NadekoBot
|
||||
{
|
||||
AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
|
||||
|
||||
var localization = new Localization(BotConfig.Locale, AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.Locale), Db);
|
||||
var localization = new Localization(_botConfig.Locale, AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.Locale), Db);
|
||||
|
||||
//initialize Services
|
||||
Services = new NServiceProvider.ServiceProviderBuilder()
|
||||
.AddManual<IBotCredentials>(Credentials)
|
||||
.AddManual(Db)
|
||||
.AddManual(BotConfig)
|
||||
.AddManual(_botConfig)
|
||||
.AddManual(Client)
|
||||
.AddManual(CommandService)
|
||||
.AddManual<ILocalization>(localization)
|
||||
|
@ -91,8 +91,4 @@
|
||||
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
|
||||
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Utility\Modules\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -3573,4 +3573,13 @@
|
||||
<data name="streamrolewhitelist_desc" xml:space="preserve">
|
||||
<value>Adds or removes a whitelisted user. Whitelisted users will receive the stream role even if they don't have the specified keyword in their stream title.</value>
|
||||
</data>
|
||||
<data name="botconfigedit_cmd" xml:space="preserve">
|
||||
<value>botconfigedit bce</value>
|
||||
</data>
|
||||
<data name="botconfigedit_usage" xml:space="preserve">
|
||||
<value>`{0}bce CurrencyName b1nzy` or `{0}bce`</value>
|
||||
</data>
|
||||
<data name="botconfigedit_desc" xml:space="preserve">
|
||||
<value>Sets one of available bot config settings to a specified value. Use the command without any parameters to get a list of available settings.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
@ -50,7 +50,7 @@ namespace NadekoBot.Services
|
||||
public ConcurrentHashSet<ulong> UsersOnShortCooldown { get; } = new ConcurrentHashSet<ulong>();
|
||||
private readonly Timer _clearUsersOnShortCooldown;
|
||||
|
||||
public CommandHandler(DiscordSocketClient client, DbService db, BotConfig bc, IEnumerable<GuildConfig> gcs, CommandService commandService, IBotCredentials credentials, NadekoBot bot)
|
||||
public CommandHandler(DiscordSocketClient client, DbService db, IBotConfigProvider bc, IEnumerable<GuildConfig> gcs, CommandService commandService, IBotCredentials credentials, NadekoBot bot)
|
||||
{
|
||||
_client = client;
|
||||
_commandService = commandService;
|
||||
@ -65,7 +65,7 @@ namespace NadekoBot.Services
|
||||
UsersOnShortCooldown.Clear();
|
||||
}, null, GlobalCommandsCooldown, GlobalCommandsCooldown);
|
||||
|
||||
DefaultPrefix = bc.DefaultPrefix;
|
||||
DefaultPrefix = bc.BotConfig.DefaultPrefix;
|
||||
_prefixes = gcs
|
||||
.Where(x => x.Prefix != null)
|
||||
.ToDictionary(x => x.GuildId, x => x.Prefix)
|
||||
|
@ -9,10 +9,10 @@ namespace NadekoBot.Services
|
||||
{
|
||||
public class CurrencyService : INService
|
||||
{
|
||||
private readonly BotConfig _config;
|
||||
private readonly IBotConfigProvider _config;
|
||||
private readonly DbService _db;
|
||||
|
||||
public CurrencyService(BotConfig config, DbService db)
|
||||
public CurrencyService(IBotConfigProvider config, DbService db)
|
||||
{
|
||||
_config = config;
|
||||
_db = db;
|
||||
@ -23,7 +23,7 @@ namespace NadekoBot.Services
|
||||
var success = await RemoveAsync(author.Id, reason, amount);
|
||||
|
||||
if (success && sendMessage)
|
||||
try { await author.SendErrorAsync($"`You lost:` {amount} {_config.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { }
|
||||
try { await author.SendErrorAsync($"`You lost:` {amount} {_config.BotConfig.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { }
|
||||
|
||||
return success;
|
||||
}
|
||||
@ -65,7 +65,7 @@ namespace NadekoBot.Services
|
||||
await AddAsync(author.Id, reason, amount);
|
||||
|
||||
if (sendMessage)
|
||||
try { await author.SendConfirmAsync($"`You received:` {amount} {_config.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { }
|
||||
try { await author.SendConfirmAsync($"`You received:` {amount} {_config.BotConfig.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { }
|
||||
}
|
||||
|
||||
public async Task AddAsync(ulong receiverId, string reason, long amount, IUnitOfWork uow = null)
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NadekoBot.Services.Database.Models
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NadekoBot.Services.Database.Repositories
|
||||
|
@ -1,6 +1,5 @@
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace NadekoBot.Services.Database.Repositories.Impl
|
||||
{
|
||||
|
12
src/NadekoBot/Services/IBotConfigProvider.cs
Normal file
12
src/NadekoBot/Services/IBotConfigProvider.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
public interface IBotConfigProvider : INService
|
||||
{
|
||||
BotConfig BotConfig { get; }
|
||||
void Reload();
|
||||
bool Edit(BotConfigEditType type, string newValue);
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// All services must implement this interface in order to be auto-discovered by the DI system
|
||||
|
111
src/NadekoBot/Services/Impl/BotConfigProvider.cs
Normal file
111
src/NadekoBot/Services/Impl/BotConfigProvider.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using NadekoBot.Common;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Services;
|
||||
|
||||
namespace NadekoBot.Services.Impl
|
||||
{
|
||||
public class BotConfigProvider : IBotConfigProvider
|
||||
{
|
||||
private readonly DbService _db;
|
||||
public BotConfig BotConfig { get; private set; }
|
||||
|
||||
public BotConfigProvider(DbService db, BotConfig bc)
|
||||
{
|
||||
_db = db;
|
||||
BotConfig = bc;
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
BotConfig = uow.BotConfig.GetOrCreate();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Edit(BotConfigEditType type, string newValue)
|
||||
{
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
var bc = uow.BotConfig.GetOrCreate();
|
||||
switch (type)
|
||||
{
|
||||
case BotConfigEditType.CurrencyGenerationChance:
|
||||
if (float.TryParse(newValue, out var chance)
|
||||
&& chance >= 0
|
||||
&& chance <= 1)
|
||||
{
|
||||
bc.CurrencyGenerationChance = chance;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BotConfigEditType.CurrencyGenerationCooldown:
|
||||
if (int.TryParse(newValue, out var cd) && cd >= 1)
|
||||
{
|
||||
bc.CurrencyGenerationCooldown = cd;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case BotConfigEditType.CurrencyName:
|
||||
bc.CurrencyName = newValue ?? "-";
|
||||
break;
|
||||
case BotConfigEditType.CurrencyPluralName:
|
||||
bc.CurrencyPluralName = newValue ?? bc.CurrencyName + "s";
|
||||
break;
|
||||
case BotConfigEditType.CurrencySign:
|
||||
bc.CurrencySign = newValue ?? "-";
|
||||
break;
|
||||
case BotConfigEditType.DmHelpString:
|
||||
bc.DMHelpString = string.IsNullOrWhiteSpace(newValue)
|
||||
? "-"
|
||||
: newValue;
|
||||
break;
|
||||
case BotConfigEditType.HelpString:
|
||||
bc.HelpString = string.IsNullOrWhiteSpace(newValue)
|
||||
? "-"
|
||||
: newValue;
|
||||
break;
|
||||
case BotConfigEditType.CurrencyDropAmount:
|
||||
if (int.TryParse(newValue, out var amount) && amount > 0)
|
||||
bc.CurrencyDropAmount = amount;
|
||||
else
|
||||
return false;
|
||||
break;
|
||||
case BotConfigEditType.CurrencyDropAmountMax:
|
||||
if (newValue == null)
|
||||
bc.CurrencyDropAmountMax = null;
|
||||
else if (int.TryParse(newValue, out var maxAmount) && maxAmount > 0)
|
||||
bc.CurrencyDropAmountMax = maxAmount;
|
||||
else
|
||||
return false;
|
||||
break;
|
||||
case BotConfigEditType.MinimumBetAmount:
|
||||
if (int.TryParse(newValue, out var minBetAmount) && minBetAmount > 0)
|
||||
bc.MinimumBetAmount = minBetAmount;
|
||||
else
|
||||
return false;
|
||||
break;
|
||||
case BotConfigEditType.TriviaCurrencyReward:
|
||||
if (int.TryParse(newValue, out var triviaReward) && triviaReward > 0)
|
||||
bc.TriviaCurrencyReward = triviaReward;
|
||||
else
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
BotConfig = bc;
|
||||
uow.Complete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Services.Impl
|
||||
namespace NadekoBot.Services.Impl
|
||||
{
|
||||
public class SyncPreconditionService
|
||||
{
|
||||
|
@ -1,11 +1,6 @@
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
|
@ -48,6 +48,8 @@ namespace NadekoBot.Services
|
||||
var interfaces = new HashSet<Type>(allTypes
|
||||
.Where(x => x.GetInterfaces().Contains(typeof(INService)) && x.GetTypeInfo().IsInterface));
|
||||
|
||||
var alreadyFailed = new Dictionary<Type, int>();
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
var swInstance = new Stopwatch();
|
||||
while (services.Count > 0)
|
||||
@ -71,11 +73,20 @@ namespace NadekoBot.Services
|
||||
else //if i failed getting it, add it to the end, and break
|
||||
{
|
||||
services.Enqueue(type);
|
||||
if (alreadyFailed.ContainsKey(type))
|
||||
{
|
||||
alreadyFailed[type]++;
|
||||
if (alreadyFailed[type] > 3)
|
||||
_log.Warn(type.Name + " wasn't instantiated in the first 3 attempts. Missing " + arg.Name + " type");
|
||||
}
|
||||
else
|
||||
alreadyFailed.Add(type, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (args.Count != argTypes.Length)
|
||||
continue;
|
||||
// _log.Info("Loading " + type.Name);
|
||||
swInstance.Restart();
|
||||
var instance = ctor.Invoke(args.ToArray());
|
||||
swInstance.Stop();
|
||||
|
@ -16,7 +16,6 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Common.Collections;
|
||||
using SixLabors.Primitives;
|
||||
using ImageSharp.PixelFormats;
|
||||
|
||||
namespace NadekoBot.Extensions
|
||||
{
|
||||
|
@ -626,6 +626,8 @@
|
||||
"utility_activity_users_total": "{0} users total.",
|
||||
"utility_author": "Author",
|
||||
"utility_botid": "Bot ID",
|
||||
"utility_bot_config_edit_fail": "Failed setting {0} to the value {1}",
|
||||
"utility_bot_config_edit_success": "The value of {0} is set to {1}",
|
||||
"utility_calcops": "List of functions in {0}calc command",
|
||||
"utility_channelid": "{0} of this channel is {1}",
|
||||
"utility_channel_topic": "Channel topic",
|
||||
|
Loading…
Reference in New Issue
Block a user