.sad, .smch now persist restarts. .usmch added to unset music channel, since destroying a player won't reset it, Added --start-delay option for .race command
This commit is contained in:
parent
2ea157902e
commit
60e248c78a
2051
NadekoBot.Core/Migrations/20171126024327_persist-sad-and-musicchannel.Designer.cs
generated
Normal file
2051
NadekoBot.Core/Migrations/20171126024327_persist-sad-and-musicchannel.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,46 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations
|
||||||
|
{
|
||||||
|
public partial class persistsadandmusicchannel : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MusicSettings",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
DateAdded = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||||
|
GuildConfigId = table.Column<int>(type: "INTEGER", nullable: false),
|
||||||
|
MusicChannelId = table.Column<ulong>(type: "INTEGER", nullable: true),
|
||||||
|
SongAutoDelete = table.Column<bool>(type: "INTEGER", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MusicSettings", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MusicSettings_GuildConfigs_GuildConfigId",
|
||||||
|
column: x => x.GuildConfigId,
|
||||||
|
principalTable: "GuildConfigs",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MusicSettings_GuildConfigId",
|
||||||
|
table: "MusicSettings",
|
||||||
|
column: "GuildConfigId",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MusicSettings");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,8 @@ using NadekoBot.Common.Attributes;
|
|||||||
using NadekoBot.Modules.Gambling.Common.AnimalRacing.Exceptions;
|
using NadekoBot.Modules.Gambling.Common.AnimalRacing.Exceptions;
|
||||||
using NadekoBot.Modules.Gambling.Common.AnimalRacing;
|
using NadekoBot.Modules.Gambling.Common.AnimalRacing;
|
||||||
using NadekoBot.Modules.Gambling.Services;
|
using NadekoBot.Modules.Gambling.Services;
|
||||||
|
using NadekoBot.Core.Modules.Gambling.Common.AnimalRacing;
|
||||||
|
using CommandLine;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Gambling
|
namespace NadekoBot.Modules.Gambling
|
||||||
{
|
{
|
||||||
@ -33,9 +35,13 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public Task Race()
|
public Task Race(params string[] args)
|
||||||
{
|
{
|
||||||
var ar = new AnimalRace(_cs, _bc.BotConfig.RaceAnimals.Shuffle().ToArray());
|
var options = new RaceOptions();
|
||||||
|
var res = Parser.Default.ParseArguments<RaceOptions>(args);
|
||||||
|
res.MapResult(x => options, x => options);
|
||||||
|
|
||||||
|
var ar = new AnimalRace(options, _cs, _bc.BotConfig.RaceAnimals.Shuffle().ToArray());
|
||||||
if (!_service.AnimalRaces.TryAdd(Context.Guild.Id, ar))
|
if (!_service.AnimalRaces.TryAdd(Context.Guild.Id, ar))
|
||||||
return Context.Channel.SendErrorAsync(GetText("animal_race"), GetText("animal_race_already_started"));
|
return Context.Channel.SendErrorAsync(GetText("animal_race"), GetText("animal_race_already_started"));
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ using System.Collections.Immutable;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using NadekoBot.Core.Modules.Gambling.Common.AnimalRacing;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Gambling.Common.AnimalRacing
|
namespace NadekoBot.Modules.Gambling.Common.AnimalRacing
|
||||||
{
|
{
|
||||||
@ -36,12 +37,15 @@ namespace NadekoBot.Modules.Gambling.Common.AnimalRacing
|
|||||||
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
|
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
|
||||||
private readonly HashSet<AnimalRacingUser> _users = new HashSet<AnimalRacingUser>();
|
private readonly HashSet<AnimalRacingUser> _users = new HashSet<AnimalRacingUser>();
|
||||||
private readonly CurrencyService _currency;
|
private readonly CurrencyService _currency;
|
||||||
|
private readonly RaceOptions _options;
|
||||||
private readonly Queue<RaceAnimal> _animalsQueue;
|
private readonly Queue<RaceAnimal> _animalsQueue;
|
||||||
public int MaxUsers { get; }
|
public int MaxUsers { get; }
|
||||||
|
|
||||||
public AnimalRace(CurrencyService currency, RaceAnimal[] availableAnimals)
|
public AnimalRace(RaceOptions options, CurrencyService currency, RaceAnimal[] availableAnimals)
|
||||||
{
|
{
|
||||||
|
NormalizeOptions(options);
|
||||||
this._currency = currency;
|
this._currency = currency;
|
||||||
|
this._options = options;
|
||||||
this._animalsQueue = new Queue<RaceAnimal>(availableAnimals);
|
this._animalsQueue = new Queue<RaceAnimal>(availableAnimals);
|
||||||
this.MaxUsers = availableAnimals.Length;
|
this.MaxUsers = availableAnimals.Length;
|
||||||
|
|
||||||
@ -49,11 +53,17 @@ namespace NadekoBot.Modules.Gambling.Common.AnimalRacing
|
|||||||
CurrentPhase = Phase.Ended;
|
CurrentPhase = Phase.Ended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void NormalizeOptions(RaceOptions options)
|
||||||
|
{
|
||||||
|
if (options.StartDelay < 10 || options.StartDelay > 120)
|
||||||
|
options.StartDelay = 20;
|
||||||
|
}
|
||||||
|
|
||||||
public void Initialize() //lame name
|
public void Initialize() //lame name
|
||||||
{
|
{
|
||||||
var _t = Task.Run(async () =>
|
var _t = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(_startingDelayMiliseconds).ConfigureAwait(false);
|
await Task.Delay(_options.StartDelay * 1000).ConfigureAwait(false);
|
||||||
|
|
||||||
await _locker.WaitAsync().ConfigureAwait(false);
|
await _locker.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
using CommandLine;
|
||||||
|
|
||||||
|
namespace NadekoBot.Core.Modules.Gambling.Common.AnimalRacing
|
||||||
|
{
|
||||||
|
public class RaceOptions
|
||||||
|
{
|
||||||
|
[Option("start-delay", Default = 20, Required = false)]
|
||||||
|
public int StartDelay { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ using NadekoBot.Common.Collections;
|
|||||||
using NadekoBot.Modules.Music.Services;
|
using NadekoBot.Modules.Music.Services;
|
||||||
using NadekoBot.Core.Services;
|
using NadekoBot.Core.Services;
|
||||||
using NadekoBot.Core.Services.Database.Models;
|
using NadekoBot.Core.Services.Database.Models;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Music.Common
|
namespace NadekoBot.Modules.Music.Common
|
||||||
{
|
{
|
||||||
@ -25,6 +26,8 @@ namespace NadekoBot.Modules.Music.Common
|
|||||||
{
|
{
|
||||||
private readonly Thread _player;
|
private readonly Thread _player;
|
||||||
public IVoiceChannel VoiceChannel { get; private set; }
|
public IVoiceChannel VoiceChannel { get; private set; }
|
||||||
|
|
||||||
|
private readonly ITextChannel _originalTextChannel;
|
||||||
private readonly Logger _log;
|
private readonly Logger _log;
|
||||||
|
|
||||||
private MusicQueue Queue { get; } = new MusicQueue();
|
private MusicQueue Queue { get; } = new MusicQueue();
|
||||||
@ -130,15 +133,19 @@ namespace NadekoBot.Modules.Music.Common
|
|||||||
: new TimeSpan(songs.Sum(s => s.TotalTime.Ticks));
|
: new TimeSpan(songs.Sum(s => s.TotalTime.Ticks));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public MusicPlayer(MusicService musicService, IGoogleApiService google, IVoiceChannel vch, ITextChannel output, float volume)
|
public MusicPlayer(MusicService musicService, MusicSettings ms, IGoogleApiService google,
|
||||||
|
IVoiceChannel vch, ITextChannel original, float volume)
|
||||||
{
|
{
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
this.Volume = volume;
|
this.Volume = volume;
|
||||||
this.VoiceChannel = vch;
|
this.VoiceChannel = vch;
|
||||||
|
this._originalTextChannel = original;
|
||||||
this.SongCancelSource = new CancellationTokenSource();
|
this.SongCancelSource = new CancellationTokenSource();
|
||||||
this.OutputTextChannel = output;
|
if(ms.MusicChannelId is ulong cid)
|
||||||
|
{
|
||||||
|
this.OutputTextChannel = ((SocketGuild)original.Guild).GetTextChannel(cid) ?? original;
|
||||||
|
}
|
||||||
this._musicService = musicService;
|
this._musicService = musicService;
|
||||||
this._google = google;
|
this._google = google;
|
||||||
|
|
||||||
@ -657,6 +664,11 @@ namespace NadekoBot.Modules.Music.Common
|
|||||||
public SongInfo MoveSong(int n1, int n2)
|
public SongInfo MoveSong(int n1, int n2)
|
||||||
=> Queue.MoveSong(n1, n2);
|
=> Queue.MoveSong(n1, n2);
|
||||||
|
|
||||||
|
public void SetMusicChannelToOriginal()
|
||||||
|
{
|
||||||
|
this.OutputTextChannel = _originalTextChannel;
|
||||||
|
}
|
||||||
|
|
||||||
//// this should be written better
|
//// this should be written better
|
||||||
//public TimeSpan TotalPlaytime =>
|
//public TimeSpan TotalPlaytime =>
|
||||||
// _playlist.Any(s => s.TotalTime == TimeSpan.MaxValue) ?
|
// _playlist.Any(s => s.TotalTime == TimeSpan.MaxValue) ?
|
||||||
|
@ -15,6 +15,7 @@ using NadekoBot.Modules.Music.Common;
|
|||||||
using NadekoBot.Modules.Music.Common.Exceptions;
|
using NadekoBot.Modules.Music.Common.Exceptions;
|
||||||
using NadekoBot.Modules.Music.Common.SongResolver;
|
using NadekoBot.Modules.Music.Common.SongResolver;
|
||||||
using NadekoBot.Common.Collections;
|
using NadekoBot.Common.Collections;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Music.Services
|
namespace NadekoBot.Modules.Music.Services
|
||||||
{
|
{
|
||||||
@ -27,6 +28,7 @@ namespace NadekoBot.Modules.Music.Services
|
|||||||
private readonly ILocalization _localization;
|
private readonly ILocalization _localization;
|
||||||
private readonly DbService _db;
|
private readonly DbService _db;
|
||||||
private readonly Logger _log;
|
private readonly Logger _log;
|
||||||
|
private readonly ConcurrentDictionary<ulong, MusicSettings> _musicSettings;
|
||||||
private readonly SoundCloudApiService _sc;
|
private readonly SoundCloudApiService _sc;
|
||||||
private readonly IBotCredentials _creds;
|
private readonly IBotCredentials _creds;
|
||||||
private readonly ConcurrentDictionary<ulong, float> _defaultVolumes;
|
private readonly ConcurrentDictionary<ulong, float> _defaultVolumes;
|
||||||
@ -49,6 +51,8 @@ namespace NadekoBot.Modules.Music.Services
|
|||||||
_sc = sc;
|
_sc = sc;
|
||||||
_creds = creds;
|
_creds = creds;
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
|
_musicSettings = bot.AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.MusicSettings)
|
||||||
|
.ToConcurrent();
|
||||||
|
|
||||||
_client.LeftGuild += _client_LeftGuild;
|
_client.LeftGuild += _client_LeftGuild;
|
||||||
|
|
||||||
@ -110,7 +114,10 @@ namespace NadekoBot.Modules.Music.Services
|
|||||||
return MusicPlayers.GetOrAdd(guildId, _ =>
|
return MusicPlayers.GetOrAdd(guildId, _ =>
|
||||||
{
|
{
|
||||||
var vol = GetDefaultVolume(guildId);
|
var vol = GetDefaultVolume(guildId);
|
||||||
var mp = new MusicPlayer(this, _google, voiceCh, textCh, vol);
|
if (!_musicSettings.TryGetValue(guildId, out var ms))
|
||||||
|
ms = new MusicSettings();
|
||||||
|
|
||||||
|
var mp = new MusicPlayer(this, ms, _google, voiceCh, textCh, vol);
|
||||||
|
|
||||||
IUserMessage playingMessage = null;
|
IUserMessage playingMessage = null;
|
||||||
IUserMessage lastFinishedMessage = null;
|
IUserMessage lastFinishedMessage = null;
|
||||||
@ -264,5 +271,10 @@ namespace NadekoBot.Modules.Music.Services
|
|||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateSettings(ulong id, MusicSettings musicSettings)
|
||||||
|
{
|
||||||
|
_musicSettings.AddOrUpdate(id, musicSettings, delegate { return musicSettings; });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AngleSharp" Version="0.9.9" />
|
<PackageReference Include="AngleSharp" Version="0.9.9" />
|
||||||
|
<PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
|
||||||
<PackageReference Include="Discord.Net" Version="2.0.0-alpha-build-00839" />
|
<PackageReference Include="Discord.Net" Version="2.0.0-alpha-build-00839" />
|
||||||
<PackageReference Include="CoreCLR-NCalc" Version="2.1.3" />
|
<PackageReference Include="CoreCLR-NCalc" Version="2.1.3" />
|
||||||
<PackageReference Include="Google.Apis.Urlshortener.v1" Version="1.29.1.138" />
|
<PackageReference Include="Google.Apis.Urlshortener.v1" Version="1.29.1.138" />
|
||||||
|
@ -92,8 +92,7 @@ namespace NadekoBot.Core.Services.Database.Models
|
|||||||
public XpSettings XpSettings { get; set; }
|
public XpSettings XpSettings { get; set; }
|
||||||
public List<FeedSub> FeedSubs { get; set; } = new List<FeedSub>();
|
public List<FeedSub> FeedSubs { get; set; } = new List<FeedSub>();
|
||||||
public bool AutoDcFromVc { get; set; }
|
public bool AutoDcFromVc { get; set; }
|
||||||
|
public MusicSettings MusicSettings { get; set; } = new MusicSettings();
|
||||||
//public List<ProtectionIgnoredChannel> ProtectionIgnoredChannels { get; set; } = new List<ProtectionIgnoredChannel>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NsfwBlacklitedTag : DbEntity
|
public class NsfwBlacklitedTag : DbEntity
|
||||||
|
11
NadekoBot.Core/Services/Database/Models/MusicSettings.cs
Normal file
11
NadekoBot.Core/Services/Database/Models/MusicSettings.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace NadekoBot.Core.Services.Database.Models
|
||||||
|
{
|
||||||
|
public class MusicSettings : DbEntity
|
||||||
|
{
|
||||||
|
public int GuildConfigId { get; set; }
|
||||||
|
public GuildConfig GuildConfig { get; set; }
|
||||||
|
|
||||||
|
public bool SongAutoDelete { get; set; } = false;
|
||||||
|
public ulong? MusicChannelId { get; set; } = null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user