forked from serpis/pynik
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
> Bytes on the outside, unicode on the inside > Encode/decode at the edges http://nedbatchelder.com/text/unipain/unipain.html#35 Close #11. Close #12.
- Loading branch information
Showing
12 changed files
with
84 additions
and
225 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
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,31 @@ | ||
# coding: utf-8 | ||
|
||
from __future__ import unicode_literals | ||
from commands import Command | ||
import chardet | ||
|
||
class DetectEncodingCommmand(Command): | ||
hooks = ['on_raw_privmsg'] | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def trig_chardet(self, bot, source, target, message, raw_line): | ||
"""Detect your encoding. Usage: .chardet text with åäö (alias: .åäö)""" | ||
|
||
def on_raw_privmsg(self, bot, source, target, message, raw_line): | ||
triggers = ['chardet', 'åäö'] | ||
|
||
if not any([message.startswith('.%s' % (trigger)) for trigger in triggers]): | ||
return | ||
|
||
message_out = detect_encoding(raw_line) | ||
bot.tell(target, message_out) | ||
|
||
def detect_encoding(raw_line): | ||
result = chardet.detect(raw_line) | ||
encoding = result["encoding"].upper() | ||
confidence = int(result["confidence"] * 100) | ||
message_out = "Du använder nog %s (%s%% säker)" % (encoding, confidence) | ||
return message_out | ||
|
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.