X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=blobdiff_plain;f=DiscordContext.pm;fp=DiscordContext.pm;h=c6e4959a2343c2e700661dc33c8f5096da0f142e;hp=0000000000000000000000000000000000000000;hb=468a4e3e07c0d9e6ed66a75c73f0d7ff2921b90a;hpb=cd18307dc7e3886266937935feffbb41b1df422d diff --git a/DiscordContext.pm b/DiscordContext.pm new file mode 100644 index 0000000..c6e4959 --- /dev/null +++ b/DiscordContext.pm @@ -0,0 +1,95 @@ +#************************************************************************** +# 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 * +# the Free Software Foundation; either version 2 of the License, or * +# (at your option) any later version. * +# * +# This program is distributed in the hope that it will be useful, * +# but WITHOUT ANY WARRANTY; without even the implied warranty of * +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# GNU General Public License for more details. * +# * +# You should have received a copy of the GNU General Public License * +# along with this program; if not, write to the * +# Free Software Foundation, Inc., * +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +#**************************************************************************/ + +package NDIRC::DiscordContext; +use strict; +use warnings; +use feature ':5.10'; + +use Moose; +use namespace::autoclean; +extends "NDIRC::Context"; + +has discord_id => ( + is => 'ro', + isa => 'Str', + required => 1 +); + +has channel_id => ( + is => 'ro', + isa => 'Str', + required => 1 +); + +has discord => ( + is => 'ro', + isa => 'Object', + required => 1 +); + + +sub reply { + my ($self,$msg) = @_; + + $self->message($self->channel_id, $msg); +} + +sub message { + my ($self, $target, $msg) = @_; + + $self->bot->discordMessage($target, $msg ); # Send the response. +} + +sub replyId { + my $self = shift; + return "D-".$self->channel_id; +} + +sub _build_uid { + my ($self) = @_; + + my $query = $self->model->prepare(q{ +SELECT uid FROM users +WHERE discord_id = $1 + }); + $query->execute($self->discord_id); + + if (my ($uid) = $query->fetchrow_array){ + $query->finish; + return $uid; + } + return -4; +} + +sub valuecolor { + shift @_; + my $s = $_; + $s = $_[1] if $#_ >= 1; + $s = "" unless defined $s; + return "~~$s~~" if $s eq 'Hostile'; + return "***$s***" if $s eq 'Friendly'; + return "*$s*" if $s eq 'Nap' or $s eq 'NAP'; + return "$s" if $_[0] && $s; + return $s; +} + +__PACKAGE__->meta->make_immutable; + +1;