Beispiel #1
0
    def paste(self, bot, update):
        bot_user = self.get_user(update)

        bot.send_chat_action(chat_id=update.message.chat_id,
                             action=ChatAction.TYPING)

        _source = Paste(source=update.message.text,
                        name='Untitled',
                        language='auto',
                        author=bot_user,
                        created_using_bot=True)

        try:
            _source.save()

            _source.alias = hashlib.md5(str(
                _source.id).encode()).hexdigest()[:8]
            _source.save()

            text = _('paste_message').format(prepare_source_link(
                _source.alias))

            update.message.reply_text(text)
        except Error:
            update.message.reply_text(_('something_went_wrong'))
    def create(self, validated_data):
        try:
            language = guess_lexer(validated_data['source']).name
        except ClassNotFound:
            language = 'undefined'

        source = Paste(name=validated_data['name'],
                       source=validated_data['source'],
                       language=language)
        source.save()

        source.alias = hashlib.md5(str(source.id).encode()).hexdigest()[:8]
        source.save()

        return source