Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement /gif command (using rightgif) #6090

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ rocketchat:slackbridge
rocketchat:slashcommands-archive
rocketchat:slashcommands-asciiarts
rocketchat:slashcommands-create
rocketchat:slashcommands-gif
rocketchat:slashcommands-invite
rocketchat:slashcommands-invite-all
rocketchat:slashcommands-join
Expand Down
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ rocketchat:slackbridge@0.0.1
rocketchat:slashcommands-archive@0.0.1
rocketchat:slashcommands-asciiarts@0.0.1
rocketchat:slashcommands-create@0.0.1
rocketchat:slashcommands-gif@0.0.1
rocketchat:slashcommands-invite@0.0.1
rocketchat:slashcommands-invite-all@0.0.1
rocketchat:slashcommands-join@0.0.1
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@
"From_Email": "From Email",
"From_email_warning": "<b>Warning</b>: The field <b>From</b> is subject to your mail server settings.",
"General": "General",
"gif_keyword": "Keyword for the gif",
"github_no_public_email": "You don't have any email as public email in your GitHub account",
"Give_a_unique_name_for_the_custom_oauth": "Give a unique name for the custom oauth",
"Give_the_application_a_name_This_will_be_seen_by_your_users": "Give the application a name. This will be seen by your users.",
Expand Down Expand Up @@ -1256,6 +1257,8 @@
"SlackBridge_Out_Enabled": "SlackBridge Out Enabled",
"SlackBridge_Out_Enabled_Description": "Choose whether SlackBridge should also send your messages back to Slack",
"SlackBridge_start": "@%s has started a SlackBridge import at `#%s`. We'll let you know when it's finished.",
"Slash_Gif_Description": "Display a gif provided by rightgif according to your keyword",
"Slash_Gif_Failed": "Failed to get gif from rightgif due to network problem or incorrect keyword",
"Slash_Gimme_Description": "Displays ༼ つ ◕_◕ ༽つ before your message",
"Slash_LennyFace_Description": "Displays ( ͡° ͜ʖ ͡°) after your message",
"Slash_Shrug_Description": "Displays ¯\\_(ツ)_/¯ after your message",
Expand Down
5 changes: 4 additions & 1 deletion packages/rocketchat-i18n/i18n/zh.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@
"From_Email": "从电子邮件",
"From_email_warning": "<b>警告</b>:<b>From</b> 字段来自于邮件服务器的设置。",
"General": "通用",
"gif_keyword": "动图关键词",
"github_no_public_email": "在您的GitHub上帐户中,您没有设置任何电子邮件作为公共电子邮件地址。",
"Give_a_unique_name_for_the_custom_oauth": "请给自定义 OAuth 设置一个唯一的名称",
"Give_the_application_a_name_This_will_be_seen_by_your_users": "给该应用设置一个名称。该名称将被您的用户看到。",
Expand Down Expand Up @@ -999,6 +1000,8 @@
"Site_Url": "网站地址",
"Site_Url_Description": "例如:https://chat.domain.com/",
"Skip": "跳过",
"Slash_Gif_Description": "根据你给的关键字显示一张动图(使用rightgif服务)",
"Slash_Gif_Failed": "获取动图失败!可能是网络问题,或者是你的关键词找不到 :(",
"Slash_Gimme_Description": "在您的消息前显示 ༼ つ ◕_◕ ༽つ",
"Slash_LennyFace_Description": "在您的消息后显示 ( ͡° ͜ʖ ͡°)",
"Slash_Shrug_Description": "显示¯\\ _(ツ)_ /¯在您的消息后",
Expand Down Expand Up @@ -1257,4 +1260,4 @@
"Your_mail_was_sent_to_s": "您的邮件已发送至 %s",
"Your_password_is_wrong": "密码错误!",
"Your_push_was_sent_to_s_devices": "您的推送已被送到 %s 台设备"
}
}
10 changes: 10 additions & 0 deletions packages/rocketchat-slashcommand-gif/gif-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Gif is a named function that will replace /gimme commands
* @param {Object} message - The message object
*/


RocketChat.slashCommands.add('gif', undefined, {
description: 'Slash_Gif_Description',
params: 'gif_keyword'
});
40 changes: 40 additions & 0 deletions packages/rocketchat-slashcommand-gif/gif-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Gif is a named function that will replace /gimme commands
* @param {Object} message - The message object
*/


function Gif(command, params, item) {
if (command === 'gif') {
const url = 'https://rightgif.com/search/web';

item.msg = '';
HTTP.post(url, {
headers: {
'content-type': 'application/json'
},
data: {
text: params
}
}, function(err, response) {
if (err || response.statusCode !== 200 || response.data.url === 'https://rightgif.com/public/images/error.gif') {
const currentUser = Meteor.users.findOne(Meteor.userId());
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date(),
msg: TAPi18n.__('Slash_Gif_Failed', null, currentUser.language)
});
} else {
item.attachments = [ {title: params, image_url: response.data.url} ];
item.groupable = false;
Meteor.call('sendMessage', item);
}
});
}
}

RocketChat.slashCommands.add('gif', Gif, {
description: 'Slash_Gif_Description',
params: 'gif_keyword'
});
17 changes: 17 additions & 0 deletions packages/rocketchat-slashcommand-gif/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Package.describe({
name: 'rocketchat:slashcommands-gif',
version: '0.0.1',
summary: 'Show gif from rightgif',
git: ''
});

Package.onUse(function(api) {
api.use([
'rocketchat:lib'
]);

api.use('ecmascript');

api.addFiles('gif-server.js', ['server']);
api.addFiles('gif-client.js', ['client']);
});