コード例 #1
0
        public BotMessage GetResponse(ResponseContext context)
        {
            try
            {
                const string reason = "for a common reply";

                if(context.Message.Text.Contains("it works on my machine"))
                {
                    reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "itworksonmymachine", context.Message.GetChannelId(), context.Message.GetTimeStamp());
                }
                var issuer = userApi.GetUserBySlackId(context.FormattedBotUserID());
                var recipient = userApi.GetUserBySlackId(context.Message.User.FormattedUserID);
                var seconderSlackId = context.GetSecondCousinSlackId();
                if (seconderSlackId.Equals("")) seconderSlackId = recipient.SlackId;
                var seconder = userApi.GetUserBySlackId(seconderSlackId);

                fineApi.IssueAutoFine(issuer.Id, recipient.Id, seconder.Id, reason);

                reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "fine", context.Message.GetChannelId(), context.Message.GetTimeStamp());
                reactionApi.AddReaction(ConfigurationManager.AppSettings["SeconderBotKey"], "fine", context.Message.GetChannelId(), context.Message.GetTimeStamp());

                return new BotMessage { Text = ""};
            }
            catch(Exception ex)
            {
                return this.GetExceptionResponse(ex, context.Message);
            }
        }
コード例 #2
0
        public BotMessage GetResponse(ResponseContext context)
        {
            try
            {
                List<string> slackIds = context.Message.GetSlackIdsFromMessage();

                if (slackIds.Any(x => x.Equals(context.FormattedBotUserID())))
                {
                    reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "middle_finger", context.Message.GetChannelId(), context.Message.GetTimeStamp());
                    return new BotMessage {Text = ""};
                }

                if (slackIds.Count == 0)
                {
                    reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "raised_hand", context.Message.GetChannelId(), context.Message.GetTimeStamp());
                    return new BotMessage { Text = "" };
                }

                var issuer = this.GetIssuer(context);

                string reason = this.GetReason(context);

                BotMessage botMessage = this.FineRecipients(slackIds, issuer, reason, context.Message);

                return botMessage;
            } catch (Exception ex)
            {
                return this.GetExceptionResponse(ex, context.Message);
            }
        }
コード例 #3
0
        public BotMessage GetResponse(ResponseContext context)
        {
            try
            {
                var youtubeLinkList = context.Message.GetYouTubeLinkList();
                const string reason = "for sharing the following YouTube video --> ";

                var issuer = userApi.GetUserBySlackId(context.FormattedBotUserID());
                var recipient = userApi.GetUserBySlackId(context.Message.User.FormattedUserID);
                var seconderSlackId = context.GetSecondCousinSlackId();
                if (seconderSlackId.Equals("")) seconderSlackId = recipient.SlackId;
                var seconder = userApi.GetUserBySlackId(seconderSlackId);

                for (var i = 0; i < youtubeLinkList.Count; i++)
                {
                    fineApi.IssueAutoFine(issuer.Id, recipient.Id, seconder.Id, reason + youtubeLinkList[i]);
                }

                reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "fine", context.Message.GetChannelId(), context.Message.GetTimeStamp());
                reactionApi.AddReaction(ConfigurationManager.AppSettings["SeconderBotKey"], "fine", context.Message.GetChannelId(), context.Message.GetTimeStamp());

                return new BotMessage { Text = "" };
            }
            catch (Exception ex)
            {
                return this.GetExceptionResponse(ex, context.Message);
            }
        }