X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=DiscordContext.pm;h=c6e4959a2343c2e700661dc33c8f5096da0f142e;hb=468a4e3e07c0d9e6ed66a75c73f0d7ff2921b90a;hp=1d7cb58f472b482b6e6af84dc3a89d76311bd78d;hpb=036bfadee395d5ec8bfa4e00b05077a90a8d232a;p=NDIRC.git diff --git a/DiscordContext.pm b/DiscordContext.pm index 1d7cb58..c6e4959 100644 --- a/DiscordContext.pm +++ b/DiscordContext.pm @@ -1,5 +1,5 @@ #************************************************************************** -# Copyright (C) 2009 by Michael Andreen * +# Copyright (C) 2019 by Michael Andreen * # * # This program is free software; you can redistribute it and/or modify * # it under the terms of the GNU General Public License as published by * @@ -23,8 +23,8 @@ use warnings; use feature ':5.10'; use Moose; - -use Set::Object (); +use namespace::autoclean; +extends "NDIRC::Context"; has discord_id => ( is => 'ro', @@ -38,61 +38,12 @@ has channel_id => ( required => 1 ); -has channel => ( - is => 'ro', - isa => 'Str', - required => 1 -); - -has roles => ( - is => 'ro', - isa => 'Object', - lazy_build => 1 -); - -has uid => ( - is => 'ro', - isa => 'Int', - lazy_build => 1 -); - -has disp => ( - is => 'ro', - isa => 'Object', - required => 1 -); - -has model => ( - is => 'ro', - isa => 'Object', - required => 1 -); - has discord => ( is => 'ro', isa => 'Object', required => 1 ); -sub assert_user_roles { - my ($self,@roles) = @_; - return 1 unless @roles; - - my $need = Set::Object->new(@roles); - - if ($self->roles->superset($need)){ - return 1; - } - - die "Access denied"; -} - -sub check_user_roles { - my ($self,@roles) = @_; - - local $@; - eval { $self->assert_user_roles(@roles) }; -} sub reply { my ($self,$msg) = @_; @@ -103,50 +54,12 @@ sub reply { sub message { my ($self, $target, $msg) = @_; - $msg =~ s`(.*?)`**$1**`gi; - $msg =~ s`(.*?)`*$2*`gi; - - $self->discord->send_message($target, $msg ); # Send the response. -} - -sub command { - my ($self,@command) = @_; - -} - -sub intel_log { - my ($c,$planet, $message) = @_; - my $log = $c->model->prepare_cached(q{ -INSERT INTO forum_posts (ftid,uid,message) VALUES( - (SELECT ftid FROM planets WHERE pid = $3),$1,$2) - }); - $log->execute($c->uid,$message,$planet); -} - -sub def_log { - my ($c,$call, $message) = @_; - my $log = $c->model->prepare(q{ -INSERT INTO forum_posts (ftid,uid,message) VALUES( - (SELECT ftid FROM calls WHERE call = $3),$1,$2) - }); - $log->execute($c->uid,$message,$call); + $self->bot->discordMessage($target, $msg ); # Send the response. } -sub _build_roles { - my ($self) = @_; - - my $query = $self->model->prepare(q{ -SELECT role FROM group_roles -WHERE gid IN (SELECT gid FROM groupmembers JOIN users USING (uid) - WHERE discord_id = $1) - }); - $query->execute($self->discord_id); - - my @roles; - while (my $group = $query->fetchrow_hashref){ - push @roles,$group->{role}; - } - return Set::Object->new(@roles); +sub replyId { + my $self = shift; + return "D-".$self->channel_id; } sub _build_uid { @@ -177,4 +90,6 @@ sub valuecolor { return $s; } +__PACKAGE__->meta->make_immutable; + 1;