IDEA版本彩虹屁插件idea-rainbow-fart,一个在你编程时疯狂称赞你的 IDEA扩展插件
缘起
是否听说过程序员鼓励师,不久前出了一款vscode的插件rainbow-fart,可以在写代码的时候,匹配到特定关键词就疯狂的拍你马屁。

vscode的下载尝试过,但是作为日常将IDEA作为主力生产工具的同学来说,如何体验呢? 于是假期花了一点时间,写了一个idea版本的插件idea-rainbow-fart。
使用说明
默认使用中文语音包,可以在setting里设置
打开设置:

选择第三方语音包:

可以到 https://github.com/topics/vscode-rainbow-fart 查找语音包。
点击确定生效:

原理
没啥原理,就是一款简单的idea插件,对没写过插件的我来说,需要先看下官方文档,基本上看下面这一篇就OK:
https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started.html
读取语音包
先来看下语音包的设计:
{
"name": "KugimiyaRie",
"display-name": "KugimiyaRie 钉宫理惠 (Japanese)",
"avatar": "louise.png",
"avatar-dark": "shana.png",
"version": "0.0.1",
"description": "傲娇钉宫,鞭写鞭骂",
"languages": [
"javascript"
],
"author": "zthxxx",
"gender": "female",
"locale": "jp",
"contributes": [
{
"keywords": [
"function",
"=>"
],
"voices": [
"function_01.mp3",
"function_02.mp3",
"function_03.mp3"
]
},
...
]
}
对Java来说,定义两个bean类,解析json即可:
/**
* 加载配置
*/
public static void loadConfig() {
try {
//
FartSettings settings = FartSettings.getInstance();
if (!settings.isEnable()) {
return;
}
String json = readVoicePackageJson("manifest.json");
Gson gson = new Gson();
Manifest manifest = gson.fromJson(json, Manifest.class);
// load contributes.json
if (manifest.getContributes() == null) {
String contributesText = readVoicePackageJson("contributes.json");
Manifest contributes = gson.fromJson(contributesText, Manifest.class);
if (contributes.getContributes() != null) {
manifest.setContributes(contributes.getContributes());
}
}
Context.init(manifest);
} catch (IOException e) {
}
}
监控用户输入
自定义一个Handler类继承TypedActionHandlerBase即可,需要实现的方法原型是:
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext)
chartTyped就是输入的字符,我们可以简单粗暴的将这些组合到一起即可,用一个list缓存,然后将拼接后的字符串匹配关键词。
private List<String> candidates = new ArrayList<>();
@Override
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
candidates.add(String.valueOf(charTyped));
String str = StringUtils.join(candidates, "");
try {
List<String> voices = Context.getCandidate(str);
if (!voices.isEmpty()) {
Context.play(voices);
candidates.clear();
}
}catch (Exception e){
// TODO
candidates.clear();
}
if (this.myOriginalHandler != null) {
this.myOriginalHandler.execute(editor, charTyped, dataContext);
}
}
匹配关键词更简单,将读取出来的json,放到hashmap中,然后遍历map,如果包含关键词就作为语音候选:
public static List<String> getCandidate(String inputHistory) {
final List<String> candidate = new ArrayList<>();
FartSettings settings = FartSettings.getInstance();
if (!settings.isEnable()) {
return candidate;
}
if (keyword2Voices != null) {
keyword2Voices.forEach((keyword, voices) -> {
if (inputHistory.contains(keyword)) {
candidate.addAll(voices);
}
});
}
if (candidate.isEmpty()) {
candidate.addAll(findSpecialKeyword(inputHistory));
}
return candidate;
}
如果找到候选,就播放。
播放
为了防止同时播放多个语音,我们用一个单线程线程池来搞定。播放器使用javazoom.jl.player.Player
/**
* play in a single thread pool
*/
static ExecutorService playerTheadPool;
static {
ThreadFactory playerFactory = new ThreadFactoryBuilder()
.setNameFormat("player-pool-%d").build();
playerTheadPool = new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1024), playerFactory, new ThreadPoolExecutor.AbortPolicy());
}
public static void play(List<String> voices) {
FartSettings settings = FartSettings.getInstance();
if (!settings.isEnable()) {
return;
}
// play in single thread
playerTheadPool.submit(() -> {
String file = voices.get(new Random().nextInt() % voices.size());
try {
InputStream inputStream = null;
if (StringUtils.isEmpty(settings.getCustomVoicePackage())) {
inputStream = Context.class.getResourceAsStream("/build-in-voice-chinese/" + file);
} else {
File mp3File = Paths.get(settings.getCustomVoicePackage(), file).toFile();
if (mp3File.exists()) {
try {
inputStream = new FileInputStream(mp3File);
} catch (FileNotFoundException e) {
}
} else {
return;
}
}
if (inputStream != null) {
Player player = new Player(inputStream);
player.play();
player.close();
}
} catch (JavaLayerException e) {
}
});
}
end
开源地址: https://github.com/jadepeng/idea-rainbow-fart
欢迎大家点赞!
作者:Jadepeng
出处:jqpeng的技术记事本--http://www.cnblogs.com/xiaoqi
您的支持是对博主最大的鼓励,感谢您的认真阅读。
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
IDEA版本彩虹屁插件idea-rainbow-fart,一个在你编程时疯狂称赞你的 IDEA扩展插件的更多相关文章
- 为Eclipse安装功能扩展插件
---------siwuxie095 关于 Eclipse 的下载.安装与配置,详见本人博客分类:利剑出鞘, 里面的 Eclipse的配置 本人博客( ...
- 自制Chrome扩展插件:用于重定向js
前言 作为一个前端开发, 在调试生产环境的代码时,是否苦于生产环境代码被压缩,没有sourcemap? 有没有想过将生产环境的js直接重定向为本地开发环境的js? 玩微前端时,有没有想过用本地的子应用 ...
- 认识Chrome扩展插件
1.前言 现如今的时代,绝大多数人都要跟浏览器打交道的,说到浏览器那肯定是Chrome浏览器一家独大,具体数据请看 知名流量监测机构 Statcounter 公布了 7 月份全球桌面浏览器市场份额,主 ...
- vscode安装rainbow-fart(彩虹屁)插件,程序员只能自我鼓励了!!!
2020-7-10更新 Rainbow Fart 插件现以发布到 VSCode 商店,安装过 VSIX 版本的用户请卸载之前的版本,从商店安装. 从 VSCode 扩展商店 下载并安装.(更新vsco ...
- dapper 扩展插件: Rainbow
dapper 扩展插件: Rainbow dapper 是一个效率非常高的orm 框架 ,效率要远远大于 我们大微软的EF . 它只有一个类文件,非常之小. 1,首先下载dapper 这里下 ...
- 用python爬虫写一个属于自己的彩虹屁生成器!
效果图如下:
- Sharepoint 2013列表视图和字段权限扩展插件(免费下载)!
记得2014年春节期间,有博客园的网友通过QQ向我咨询Sharepoint 2013列表视图和字段权限扩展,因为之前他看到我博客介绍Sharepoint 2010列表视图和字段的权限控制扩展使用,问有 ...
- 常用网站开发类Firefox扩展插件 (转)
作为一个 Web 开发人员,你几乎没有理由不喜欢Firefox,因为在Firefox下有很多专门针对开发的扩展插件,非常好用,这里就介绍一些常用的针对网站开发的FireFox扩展,供Web开发人员参考 ...
- 100个精选zencart扩展插件
100个精选zencart扩展插件 特别推荐 1. 数据库备份 2. 产品横向布局. 3. 邮件订阅Newsletter Subscribe. 4. google 翻译google_translate ...
随机推荐
- Rocket - debug - Example: Quick Access
https://mp.weixin.qq.com/s/SxmX-CY2tqvEqZuAg-EXiQ 介绍riscv-debug的使用实例:配置Quick Access功能. 1. Quick Acce ...
- Rocket - diplomacy - TransferSizes
https://mp.weixin.qq.com/s/Sf0owQxWzxacVvykJZ5oTQ 介绍TransferSizes的实现. 1. 基本定义 从min到max的闭合 ...
- 【HBase】知识小结+HMaster选举、故障恢复、读写流程
1:什么是HBase HBase是一个高可靠性,高性能,面向列,可伸缩的分布式数据库,提供海量数据存储功能,一个结构化的分布式存储系统,不同于一般的关系型数据库,它适合半结构化和非结构化数据存储. 2 ...
- Docker容器同步主机时间
方法一: 查看本地是否有/etc/localtime文件 cat /etc/localtime 如果没有就新建文件 cp /usr/share/zoneinfo/Asia/Shanghai /et ...
- 基于GTID搭建主从MySQL
目录 基于gtid搭建主从MySQL 一.GTID的使用 二.GTID的简介 三.GTID的构成 四.查看GTID的执行情况 4.1 gtid_executed 4.2 gtid_own 4.3 gt ...
- Java 第十一届 蓝桥杯 省模拟赛 反倍数
反倍数 题目 问题描述 给定三个整数 a, b, c,如果一个整数既不是 a 的整数倍也不是 b 的整数倍还不是 c 的整数倍,则这个数称为反倍数. 请问在 1 至 n 中有多少个反倍数. 输入格式 ...
- Java实现 蓝桥杯 算法提高 求arccos值
算法提高 7-2求arccos值 时间限制:10.0s 内存限制:256.0MB 提交此题 问题描述 利用标准库中的cos(x)和fabs(x)函数实现arccos(x)函数,x取值范围是[-1, 1 ...
- Java实现 蓝桥杯VIP 算法训练 单词接龙
问题描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的"龙"(每个单词都最多在"龙" ...
- Java实现 LeetCode 8 字符串转换整数(atoi)
8. 字符串转换整数 (atoi) 请你来实现一个 atoi 函数,使其能将字符串转换成整数. 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止. 当我们寻找到的第一个非 ...
- java实现蔬菜价格计算
** 蔬菜价格计算** 计算蔬菜总价 为了丰富群众菜篮子,平抑菜价,相关部分组织了蔬菜的调运.今某箱中有多个品种的蔬菜.蔬菜的单价(元/公斤)存放在price数组中,蔬菜的重量(公斤)存放在weigh ...