finished .streamrole

This commit is contained in:
Master Kwoth 2017-07-14 17:09:06 +02:00
parent b8573f11b5
commit 17719dd8e2
3 changed files with 34 additions and 25 deletions

View File

@ -2,38 +2,41 @@
using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.Services.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Utility.Commands
namespace NadekoBot.Modules.Utility
{
public class StreamRoleCommands : NadekoSubmodule
public partial class Utility
{
private readonly StreamRoleService service;
public StreamRoleCommands(StreamRoleService service)
public class StreamRoleCommands : NadekoSubmodule
{
this.service = service;
}
private readonly StreamRoleService service;
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task StreamRole(IRole fromRole, IRole addRole)
{
this.service.SetStreamRole(fromRole, addRole);
public StreamRoleCommands(StreamRoleService service)
{
this.service = service;
}
await ReplyConfirmLocalized("stream_role_enabled", Format.Bold(fromRole.ToString()), Format.Bold(addRole.ToString())).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireBotPermission(GuildPermission.ManageRoles)]
[RequireUserPermission(GuildPermission.ManageRoles)]
[RequireContext(ContextType.Guild)]
public async Task StreamRole(IRole fromRole, IRole addRole)
{
this.service.SetStreamRole(fromRole, addRole);
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task StreamRole()
{
this.service.StopStreamRole(Context.Guild.Id);
await ReplyConfirmLocalized("stream_role_disabled").ConfigureAwait(false);
await ReplyConfirmLocalized("stream_role_enabled", Format.Bold(fromRole.ToString()), Format.Bold(addRole.ToString())).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireBotPermission(GuildPermission.ManageRoles)]
[RequireUserPermission(GuildPermission.ManageRoles)]
[RequireContext(ContextType.Guild)]
public async Task StreamRole()
{
this.service.StopStreamRole(Context.Guild.Id);
await ReplyConfirmLocalized("stream_role_disabled").ConfigureAwait(false);
}
}
}
}
}

View File

@ -167,6 +167,7 @@ namespace NadekoBot
var patreonRewardsService = new PatreonRewardsService(Credentials, Db, Currency, Client);
var verboseErrorsService = new VerboseErrorsService(AllGuildConfigs, Db, CommandHandler, helpService);
var pruneService = new PruneService();
var streamRoleService = new StreamRoleService(Client, Db, AllGuildConfigs);
#endregion
#region permissions
@ -236,6 +237,7 @@ namespace NadekoBot
.Add(verboseErrorsService)
.Add(patreonRewardsService)
.Add(pruneService)
.Add(streamRoleService)
.Add<SearchesService>(searchesService)
.Add(streamNotificationService)
.Add(animeSearchService)

View File

@ -50,7 +50,11 @@ namespace NadekoBot.Services.Utility
{
//get needed roles
fromRole = after.Guild.GetRole(setting.FromRoleId);
if (fromRole == null)
throw new InvalidOperationException();
addRole = after.Guild.GetRole(setting.AddRoleId);
if (addRole == null)
throw new InvalidOperationException();
}
catch (Exception ex)
{