.gvc added

This commit is contained in:
Kwoth 2017-04-08 21:03:07 +02:00
parent 57e9c62b11
commit a89d00ff31
11 changed files with 1753 additions and 4 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class gamevoicechannel : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<ulong>(
name: "GameVoiceChannel",
table: "GuildConfigs",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "GameVoiceChannel",
table: "GuildConfigs");
}
}
}

View File

@ -533,6 +533,8 @@ namespace NadekoBot.Migrations
b.Property<bool>("FilterWords");
b.Property<ulong?>("GameVoiceChannel");
b.Property<ulong>("GreetMessageChannelId");
b.Property<ulong>("GuildId");

View File

@ -0,0 +1,131 @@
using Discord;
using Discord.Commands;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Attributes;
using NadekoBot.Services;
using NadekoBot.Services.Database;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Discord.WebSocket;
using NLog;
using NadekoBot.Extensions;
namespace NadekoBot.Modules.Administration
{
public partial class Administration
{
[Group]
public class GameChannelCommands : NadekoSubmodule
{
private static readonly Timer _t;
private static readonly ConcurrentHashSet<ulong> gameVoiceChannels = new ConcurrentHashSet<ulong>();
private static new readonly Logger _log;
static GameChannelCommands()
{
//_t = new Timer(_ => {
//}, null, );
_log = LogManager.GetCurrentClassLogger();
gameVoiceChannels = new ConcurrentHashSet<ulong>(
NadekoBot.AllGuildConfigs.Where(gc => gc.GameVoiceChannel != null)
.Select(gc => gc.GameVoiceChannel.Value));
NadekoBot.Client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated;
}
private static Task Client_UserVoiceStateUpdated(SocketUser usr, SocketVoiceState oldState, SocketVoiceState newState)
{
var _ = Task.Run(async () =>
{
try
{
var gUser = usr as SocketGuildUser;
if (gUser == null)
return;
var game = gUser.Game?.Name.TrimTo(50).ToLowerInvariant();
if (oldState.VoiceChannel == newState.VoiceChannel ||
newState.VoiceChannel == null)
return;
if (!gameVoiceChannels.Contains(newState.VoiceChannel.Id) ||
string.IsNullOrWhiteSpace(game))
return;
var vch = gUser.Guild.VoiceChannels
.FirstOrDefault(x => x.Name.ToLowerInvariant() == game);
if (vch == null)
return;
await Task.Delay(1000).ConfigureAwait(false);
await gUser.ModifyAsync(gu => gu.Channel = vch).ConfigureAwait(false);
}
catch (Exception ex)
{
_log.Warn(ex);
}
});
return Task.CompletedTask;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
[RequireBotPermission(GuildPermission.MoveMembers)]
public async Task GameVoiceChannel()
{
var vch = ((IGuildUser)Context.User).VoiceChannel;
if (vch == null)
{
await ReplyErrorLocalized("not_in_voice").ConfigureAwait(false);
return;
}
ulong? id;
using (var uow = DbHandler.UnitOfWork())
{
var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set);
if (gc.GameVoiceChannel == vch.Id)
{
gameVoiceChannels.TryRemove(vch.Id);
id = gc.GameVoiceChannel = null;
}
else
{
if(gc.GameVoiceChannel != null)
gameVoiceChannels.TryRemove(gc.GameVoiceChannel.Value);
gameVoiceChannels.Add(vch.Id);
id = gc.GameVoiceChannel = vch.Id;
}
uow.Complete();
}
if (id == null)
{
await ReplyConfirmLocalized("gvc_disabled").ConfigureAwait(false);
}
else
{
gameVoiceChannels.Add(vch.Id);
await ReplyConfirmLocalized("gvc_enabled", Format.Bold(vch.Name)).ConfigureAwait(false);
}
}
}
}
}

View File

@ -140,7 +140,6 @@ namespace NadekoBot.Modules.Gambling
removed = uow.Complete();
}
_log.Warn($"Removed {removed} items");
try
{
await (await Context.User.CreateDMChannelAsync())

View File

@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Music
{
[NadekoModule("Music", "!!")]
[DontAutoLoad]
public class Music : NadekoTopLevelModule
public class Music : NadekoTopLevelModule
{
public static ConcurrentDictionary<ulong, MusicPlayer> MusicPlayers { get; } = new ConcurrentDictionary<ulong, MusicPlayer>();

View File

@ -3002,6 +3002,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to gvc.
/// </summary>
public static string gamevoicechannel_cmd {
get {
return ResourceManager.GetString("gamevoicechannel_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Toggles game voice channel feature in the voice channel you&apos;re currently in. Users who join the game voice channel will get automatically redirected to the voice channel with the name of their current game if it exists. Can&apos;t move users to channels that the bot has no connect permission for. One per server..
/// </summary>
public static string gamevoicechannel_desc {
get {
return ResourceManager.GetString("gamevoicechannel_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}gvc`.
/// </summary>
public static string gamevoicechannel_usage {
get {
return ResourceManager.GetString("gamevoicechannel_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to gelbooru.
/// </summary>
@ -7629,7 +7656,7 @@ namespace NadekoBot.Resources {
}
/// <summary>
/// Looks up a localized string similar to Adds an item to the list of items for sale in the shop entry given the index..
/// Looks up a localized string similar to Adds an item to the list of items for sale in the shop entry given the index. You usually want to run this command in the secret channel, so that the unique items are not leaked..
/// </summary>
public static string shoplistadd_desc {
get {

View File

@ -3417,11 +3417,20 @@
<data name="buy_usage" xml:space="preserve">
<value>`{0}buy 2`</value>
</data>
<data name="gamevoicechannel_cmd" xml:space="preserve">
<value>gvc</value>
</data>
<data name="gamevoicechannel_desc" xml:space="preserve">
<value>Toggles game voice channel feature in the voice channel you're currently in. Users who join the game voice channel will get automatically redirected to the voice channel with the name of their current game if it exists. Can't move users to channels that the bot has no connect permission for. One per server.</value>
</data>
<data name="gamevoicechannel_usage" xml:space="preserve">
<value>`{0}gvc`</value>
</data>
<data name="shoplistadd_cmd" xml:space="preserve">
<value>shoplistadd</value>
</data>
<data name="shoplistadd_desc" xml:space="preserve">
<value>Adds an item to the list of items for sale in the shop entry given the index.</value>
<value>Adds an item to the list of items for sale in the shop entry given the index. You usually want to run this command in the secret channel, so that the unique items are not leaked.</value>
</data>
<data name="shoplistadd_usage" xml:space="preserve">
<value>`{0}shoplistadd 1 Uni-que-Steam-Key`</value>

View File

@ -519,6 +519,24 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Game Voice Channel feature has been disabled on this server..
/// </summary>
public static string administration_gvc_disabled {
get {
return ResourceManager.GetString("administration_gvc_disabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} is a Game Voice Channel now..
/// </summary>
public static string administration_gvc_enabled {
get {
return ResourceManager.GetString("administration_gvc_enabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You can&apos;t use this command on users with a role higher or equal to yours in the role hierarchy..
/// </summary>
@ -916,6 +934,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to You are not in voice channel on this server..
/// </summary>
public static string administration_not_in_voice {
get {
return ResourceManager.GetString("administration_not_in_voice", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Old message.
/// </summary>

View File

@ -2431,6 +2431,15 @@ Owner ID: {2}</value>
<value>Next update in {0}</value>
<comment>Next update in 05:30</comment>
</data>
<data name="administration_gvc_disabled" xml:space="preserve">
<value>Game Voice Channel feature has been disabled on this server.</value>
</data>
<data name="administration_gvc_enabled" xml:space="preserve">
<value>{0} is a Game Voice Channel now.</value>
</data>
<data name="administration_not_in_voice" xml:space="preserve">
<value>You are not in voice channel on this server.</value>
</data>
<data name="gambling_item" xml:space="preserve">
<value>Item</value>
</data>

View File

@ -77,6 +77,7 @@ namespace NadekoBot.Services.Database.Models
public HashSet<SlowmodeIgnoredRole> SlowmodeIgnoredRoles { get; set; }
public List<ShopEntry> ShopEntries { get; set; }
public ulong? GameVoiceChannel { get; set; } = null;
//public List<ProtectionIgnoredChannel> ProtectionIgnoredChannels { get; set; } = new List<ProtectionIgnoredChannel>();
}