-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(image-search): adding iqdb search (#143)
- Loading branch information
1 parent
9a37afe
commit 9cd9abb
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { searchPic } from 'iqdb-client' | ||
import { segment } from 'koishi-utils' | ||
import { Session } from 'koishi-core' | ||
|
||
async function makeSearch(url: string): Promise<string> { | ||
const res: any = await searchPic(url, { lib: 'www' }) | ||
if (res.ok || (res.data && res.data.length > 1)) { | ||
let data: any = res.data[1] | ||
let { head, sourceUrl, img, type, source } = data | ||
|
||
return [ | ||
segment('image', { url: 'https://iqdb.org' + img }), | ||
'准度:' + head.toLowerCase(), | ||
'来源:' + sourceUrl, | ||
'色图:' + (type.toLowerCase() === 'safe' ? '否' : '是⚠️'), | ||
'源站:' + source.join(', '), | ||
].join('\n') | ||
} else if (res.err) { | ||
return '搜图时遇到问题:' + res.err | ||
} else { | ||
return '搜图时遇到未知问题。' | ||
} | ||
} | ||
|
||
export default async function(url: string, session: Session) { | ||
let result: string = 'iqdb.org 搜图\n' | ||
try { | ||
result += await makeSearch(url) | ||
} catch (err) { | ||
result += '搜图时遇到问题:' + err | ||
} | ||
return session.send(result) | ||
} |