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 Discord.Commands;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using NadekoBot.Services.Utility; using NadekoBot.Services.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; 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 class StreamRoleCommands : NadekoSubmodule
public StreamRoleCommands(StreamRoleService service)
{ {
this.service = service; private readonly StreamRoleService service;
}
[NadekoCommand, Usage, Description, Aliases] public StreamRoleCommands(StreamRoleService service)
[RequireContext(ContextType.Guild)] {
public async Task StreamRole(IRole fromRole, IRole addRole) this.service = service;
{ }
this.service.SetStreamRole(fromRole, addRole);
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] await ReplyConfirmLocalized("stream_role_enabled", Format.Bold(fromRole.ToString()), Format.Bold(addRole.ToString())).ConfigureAwait(false);
[RequireContext(ContextType.Guild)] }
public async Task StreamRole()
{ [NadekoCommand, Usage, Description, Aliases]
this.service.StopStreamRole(Context.Guild.Id); [RequireBotPermission(GuildPermission.ManageRoles)]
await ReplyConfirmLocalized("stream_role_disabled").ConfigureAwait(false); [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 patreonRewardsService = new PatreonRewardsService(Credentials, Db, Currency, Client);
var verboseErrorsService = new VerboseErrorsService(AllGuildConfigs, Db, CommandHandler, helpService); var verboseErrorsService = new VerboseErrorsService(AllGuildConfigs, Db, CommandHandler, helpService);
var pruneService = new PruneService(); var pruneService = new PruneService();
var streamRoleService = new StreamRoleService(Client, Db, AllGuildConfigs);
#endregion #endregion
#region permissions #region permissions
@ -236,6 +237,7 @@ namespace NadekoBot
.Add(verboseErrorsService) .Add(verboseErrorsService)
.Add(patreonRewardsService) .Add(patreonRewardsService)
.Add(pruneService) .Add(pruneService)
.Add(streamRoleService)
.Add<SearchesService>(searchesService) .Add<SearchesService>(searchesService)
.Add(streamNotificationService) .Add(streamNotificationService)
.Add(animeSearchService) .Add(animeSearchService)

View File

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