Bot config, playing statuses, a LOT of other stuff
This commit is contained in:
@@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Administration
|
||||
[Module(".", AppendSpace = false)]
|
||||
public partial class Administration : DiscordModule
|
||||
{
|
||||
public Administration(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
||||
public Administration(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ using NadekoBot.Attributes;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,6 +21,52 @@ namespace NadekoBot.Modules.Administration
|
||||
[Group]
|
||||
public class PlayingRotateCommands
|
||||
{
|
||||
private Logger _log { get; }
|
||||
|
||||
public PlayingRotateCommands()
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var index = 0;
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
BotConfig conf;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
conf = uow.BotConfig.GetOrCreate();
|
||||
}
|
||||
|
||||
if (!conf.RotatingStatuses)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
if (index >= conf.RotatingStatusMessages.Count)
|
||||
index = 0;
|
||||
|
||||
if (!conf.RotatingStatusMessages.Any())
|
||||
continue;
|
||||
|
||||
await NadekoBot.Client
|
||||
.GetCurrentUser()
|
||||
.ModifyStatusAsync(mpp => mpp.Game = new Game(conf.RotatingStatusMessages[index++].Status))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warn("Rotating playing status errored.\n" + ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Task.Delay(15000);
|
||||
}
|
||||
} while (true);
|
||||
});
|
||||
}
|
||||
|
||||
public static Dictionary<string, Func<string>> PlayingPlaceholders { get; } =
|
||||
new Dictionary<string, Func<string>> {
|
||||
{"%servers%", () => NadekoBot.Client.GetGuilds().Count().ToString()},
|
||||
@@ -45,28 +92,34 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
bool status;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
var config = uow.BotConfig.GetOrCreate();
|
||||
|
||||
config.RotatingStatuses = !config.RotatingStatuses;
|
||||
status = config.RotatingStatuses = !config.RotatingStatuses;
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
if (status)
|
||||
await channel.SendMessageAsync("`Rotating playing status enabled.`");
|
||||
else
|
||||
await channel.SendMessageAsync("`Rotating playing status disabled.`");
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task AddPlaying(IMessage imsg, string status)
|
||||
public async Task AddPlaying(IMessage imsg, [Remainder] string status)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
var config = uow.BotConfig.GetOrCreate();
|
||||
config.RotatingStatusMessages.Add(new PlayingStatus { Status = status });
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
|
||||
await channel.SendMessageAsync("`Added.`").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
@@ -78,7 +131,7 @@ namespace NadekoBot.Modules.Administration
|
||||
List<PlayingStatus> statuses;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
statuses = uow.GuildConfigs.For(channel.Guild.Id).RotatingStatusMessages;
|
||||
statuses = uow.BotConfig.GetOrCreate().RotatingStatusMessages;
|
||||
}
|
||||
|
||||
if (!statuses.Any())
|
||||
@@ -86,7 +139,7 @@ namespace NadekoBot.Modules.Administration
|
||||
else
|
||||
{
|
||||
var i = 1;
|
||||
await channel.SendMessageAsync($"{imsg.Author.Mention} Here is a list of rotating statuses:\n" + string.Join("\n", statuses.Select(rs => $"`{i++}.` {rs.Status}\n")));
|
||||
await channel.SendMessageAsync($"{imsg.Author.Mention} `Here is a list of rotating statuses:`\n\n\t" + string.Join("\n\t", statuses.Select(rs => $"`{i++}.` {rs.Status}")));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -96,17 +149,20 @@ namespace NadekoBot.Modules.Administration
|
||||
public async Task RemovePlaying(IMessage imsg, int index)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
index -= 1;
|
||||
|
||||
string msg = "";
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
var config = uow.BotConfig.GetOrCreate();
|
||||
|
||||
if (index >= config.RotatingStatusMessages.Count)
|
||||
return;
|
||||
|
||||
msg = config.RotatingStatusMessages[index].Status;
|
||||
config.RotatingStatusMessages.RemoveAt(index);
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
await channel.SendMessageAsync($"`Removed the the playing message:` {msg}").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
@@ -62,7 +62,7 @@ namespace NadekoBot.Modules.Administration
|
||||
success = uow.SelfAssignedRoles.DeleteByGuildAndRoleId(role.GuildId, role.Id);
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
if (success)
|
||||
if (!success)
|
||||
{
|
||||
await channel.SendMessageAsync(":anger:That role is not self-assignable.").ConfigureAwait(false);
|
||||
return;
|
||||
@@ -183,7 +183,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Iamnot(IMessage imsg, IRole role)
|
||||
public async Task Iamnot(IMessage imsg, [Remainder] IRole role)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
var guildUser = (IGuildUser)imsg.Author;
|
||||
|
@@ -20,7 +20,7 @@ namespace NadekoBot.Modules.ClashOfClans
|
||||
{
|
||||
public static ConcurrentDictionary<ulong, List<ClashWar>> ClashWars { get; set; } = new ConcurrentDictionary<ulong, List<ClashWar>>();
|
||||
|
||||
public ClashOfClans(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
||||
public ClashOfClans(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||
{
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
|
@@ -10,15 +10,13 @@ namespace NadekoBot.Modules
|
||||
{
|
||||
protected ILocalization _l;
|
||||
protected CommandService _commands;
|
||||
protected IBotConfiguration _config;
|
||||
protected DiscordSocketClient _client;
|
||||
protected Logger _log;
|
||||
|
||||
public DiscordModule(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client)
|
||||
public DiscordModule(ILocalization loc, CommandService cmds, DiscordSocketClient client)
|
||||
{
|
||||
_l = loc;
|
||||
_commands = cmds;
|
||||
_config = config;
|
||||
_client = client;
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
@@ -2,6 +2,8 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -63,7 +65,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
public class AnimalRace
|
||||
{
|
||||
|
||||
private ConcurrentQueue<string> animals = new ConcurrentQueue<string>(NadekoBot.Config.RaceAnimals.Shuffle());
|
||||
private ConcurrentQueue<string> animals { get; }
|
||||
|
||||
public bool Fail { get; internal set; }
|
||||
|
||||
@@ -83,6 +85,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
Fail = true;
|
||||
return;
|
||||
}
|
||||
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
animals = new ConcurrentQueue<string>(uow.BotConfig.GetOrCreate().RaceAnimals.Select(ra=>ra.Icon).Shuffle());
|
||||
}
|
||||
|
||||
|
||||
var cancelSource = new CancellationTokenSource();
|
||||
var token = cancelSource.Token;
|
||||
var fullgame = CheckForFullGameAsync(token);
|
||||
@@ -184,7 +193,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
var wonAmount = winner.AmountBet * (participants.Count - 1);
|
||||
//todo DB
|
||||
//await FlowersHandler.AddFlowersAsync(winner.User, "Won a Race", wonAmount).ConfigureAwait(false);
|
||||
await raceChannel.SendMessageAsync($"🏁 {winner.User.Mention} as {winner.Animal} **Won the race and {wonAmount}{NadekoBot.Config.Currency.Sign}!**").ConfigureAwait(false);
|
||||
await raceChannel.SendMessageAsync($"🏁 {winner.User.Mention} as {winner.Animal} **Won the race and {wonAmount}{CurrencySign}!**").ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -228,7 +237,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
return false;
|
||||
}
|
||||
participants.Add(p);
|
||||
await raceChannel.SendMessageAsync($"{u.Mention} **joined the race as a {p.Animal}" + (amount > 0 ? $" and bet {amount} {(amount == 1? NadekoBot.Config.Currency.Name: NadekoBot.Config.Currency.PluralName)}!**" : "**"));
|
||||
await raceChannel.SendMessageAsync($"{u.Mention} **joined the race as a {p.Animal}" + (amount > 0 ? $" and bet {amount} {(amount == 1? CurrencyName : CurrencyPluralName)}!**" : "**"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Services;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Services.Database;
|
||||
|
||||
//todo DB
|
||||
namespace NadekoBot.Modules.Gambling
|
||||
@@ -15,8 +16,21 @@ namespace NadekoBot.Modules.Gambling
|
||||
[Module("$", AppendSpace = false)]
|
||||
public partial class Gambling : DiscordModule
|
||||
{
|
||||
public Gambling(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
||||
public static string CurrencyName { get; set; }
|
||||
public static string CurrencyPluralName { get; set; }
|
||||
public static string CurrencySign { get; set; }
|
||||
|
||||
public Gambling(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||
{
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var conf = uow.BotConfig.GetOrCreate();
|
||||
|
||||
CurrencyName = conf.CurrencyName;
|
||||
CurrencySign = conf.CurrencySign;
|
||||
CurrencyPluralName = conf.CurrencyPluralName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
|
@@ -8,6 +8,7 @@ using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using NadekoBot.Extensions;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Services.Database;
|
||||
|
||||
namespace NadekoBot.Modules.Games
|
||||
{
|
||||
@@ -15,10 +16,16 @@ namespace NadekoBot.Modules.Games
|
||||
public partial class Games : DiscordModule
|
||||
{
|
||||
//todo DB
|
||||
private IEnumerable<string> _8BallResponses;
|
||||
public Games(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
||||
private IEnumerable<string> _8BallResponses {
|
||||
get {
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
return uow.BotConfig.GetOrCreate().EightBallResponses.Select(ebr => ebr.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
public Games(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||
{
|
||||
_8BallResponses = config.EightBallResponses;
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
|
@@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Help
|
||||
return str + String.Format(str, NadekoBot.Credentials.ClientId);
|
||||
}
|
||||
}
|
||||
public Help(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
||||
public Help(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Music
|
||||
public const string MusicDataPath = "data/musicdata";
|
||||
private IGoogleApiService _google;
|
||||
|
||||
public Music(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client, IGoogleApiService google) : base(loc, cmds, config, client)
|
||||
public Music(ILocalization loc, CommandService cmds, DiscordSocketClient client, IGoogleApiService google) : base(loc, cmds, client)
|
||||
{
|
||||
//it can fail if its currenctly opened or doesn't exist. Either way i don't care
|
||||
try { Directory.Delete(MusicDataPath, true); } catch { }
|
||||
|
@@ -18,7 +18,7 @@ namespace NadekoBot.Modules.NSFW
|
||||
[Module("~", AppendSpace = false)]
|
||||
public class NSFW : DiscordModule
|
||||
{
|
||||
public NSFW(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
||||
public NSFW(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@ namespace NadekoBot.Modules.Games
|
||||
[Module(">", AppendSpace = false)]
|
||||
public partial class Pokemon : DiscordModule
|
||||
{
|
||||
public Pokemon(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
||||
public Pokemon(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Searches
|
||||
{
|
||||
private IGoogleApiService _google { get; }
|
||||
|
||||
public Searches(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client, IGoogleApiService youtube) : base(loc, cmds, config, client)
|
||||
public Searches(ILocalization loc, CommandService cmds, DiscordSocketClient client, IGoogleApiService youtube) : base(loc, cmds, client)
|
||||
{
|
||||
_google = youtube;
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ namespace NadekoBot.Modules.Translator
|
||||
[Module("~", AppendSpace = false)]
|
||||
public class Translator : DiscordModule
|
||||
{
|
||||
public Translator(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
||||
public Translator(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,8 @@ namespace NadekoBot.Modules.Utility
|
||||
Regex regex = new Regex(@"^(?:(?<months>\d)mo)?(?:(?<weeks>\d)w)?(?:(?<days>\d{1,2})d)?(?:(?<hours>\d{1,2})h)?(?:(?<minutes>\d{1,2})m)?$",
|
||||
RegexOptions.Compiled | RegexOptions.Multiline);
|
||||
|
||||
private string RemindMessageFormat { get; }
|
||||
|
||||
IDictionary<string, Func<Reminder, string>> replacements = new Dictionary<string, Func<Reminder, string>>
|
||||
{
|
||||
{ "%message%" , (r) => r.Message },
|
||||
@@ -36,6 +38,8 @@ namespace NadekoBot.Modules.Utility
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
reminders = uow.Reminders.GetAll().ToList();
|
||||
|
||||
RemindMessageFormat = uow.BotConfig.GetOrCreate().RemindMessageFormat;
|
||||
}
|
||||
|
||||
foreach (var r in reminders)
|
||||
@@ -74,7 +78,7 @@ namespace NadekoBot.Modules.Utility
|
||||
return;
|
||||
|
||||
await ch.SendMessageAsync(
|
||||
replacements.Aggregate(NadekoBot.Config.RemindMessageFormat,
|
||||
replacements.Aggregate(RemindMessageFormat,
|
||||
(cur, replace) => cur.Replace(replace.Key, replace.Value(r)))
|
||||
).ConfigureAwait(false); //it works trust me
|
||||
|
||||
|
@@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Utility
|
||||
[Module(".", AppendSpace = false)]
|
||||
public partial class Utility : DiscordModule
|
||||
{
|
||||
public Utility(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client)
|
||||
public Utility(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -129,6 +129,19 @@ namespace NadekoBot.Modules.Utility
|
||||
}
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ChannelTopic(IMessage imsg)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
var topic = channel.Topic;
|
||||
if (string.IsNullOrWhiteSpace(topic))
|
||||
await channel.SendMessageAsync("`No topic set.`");
|
||||
else
|
||||
await channel.SendMessageAsync("`Topic:` " + topic);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Stats(IMessage imsg)
|
||||
|
Reference in New Issue
Block a user